Example #1
0
int listMapped(Display *display, const char *arg) {
    int one = strchr(arg, '1') != NULL;
    int asints = strchr(arg, 'i') != NULL;
    int names = strchr(arg, 'n') != NULL;
    int mark = strchr(arg, 'm') != NULL;

    Window parent, root, *children;
    unsigned int nchildren;
    XWindowAttributes attributes;
    char *name;

    if (!XQueryTree(display, DefaultRootWindow(display), &root, &parent,
                   &children, &nchildren))
        return 1;
    if (!children)
        return 0;

    while (nchildren--) {
        if (XGetWindowAttributes(display, children[nchildren],
                    &attributes) && attributes.map_state == IsViewable) {
            if (names) {
                if (XFetchName(display, children[nchildren], &name) && name) {
                    printf("%s ", name);
                    XFree(name);
                } else {
                    printf("Unknown ");
                }
            }
            printf(asints ? "%u" : "0x%x", (unsigned int)children[nchildren]);
            printf(mark ? "*\n" : "\n");
            mark = 0;
            if (one) {
                break;
            }
        }
    }

    XFree(children);
    return 0;
}
Example #2
0
static int bgd_get_desktop_size( INSTANCE * my, int * params )
{
#ifdef WIN32
    RECT Rect;

    if ( GetClientRect( GetDesktopWindow(), &Rect ) )
    {
        *(( int * )( params[0] ) ) = Rect.right - Rect.left;
        *(( int * )( params[1] ) ) = Rect.bottom - Rect.top;
    }
#elif __linux
#ifdef SDL_VIDEO_DRIVER_X11
    int res ;
    Window root, parent, *children = NULL;
    XWindowAttributes wattr;
    unsigned int children_count;

    SDL_SysWMinfo wminfo ;

    SDL_VERSION( &wminfo.version );
    if ( SDL_GetWMInfo( &wminfo ) != 1 ) return -1 ;

    wminfo.info.x11.lock_func();
    if ( XQueryTree(wminfo.info.x11.display, wminfo.info.x11.window, &root, &parent, &children, &children_count ) != BadWindow )
    {
        if ( children ) XFree( children );

        res = XGetWindowAttributes( wminfo.info.x11.display, root, &wattr );
        if ( res != BadDrawable && res != BadWindow )
        {
            if ( params[0] ) *(( int * )( params[0] ) ) = wattr.width;
            if ( params[1] ) *(( int * )( params[1] ) ) = wattr.height;
        }
    }
    wminfo.info.x11.unlock_func();
#endif
#endif

    return 1 ;
}
Example #3
0
void Amor::restack()
{
    if( mTargetWin == None ) {
        return;
    }

    if( mConfig.mOnTop ) {
        // simply raise the widget to the top
        mAmor->raise();
        return;
    }

#if defined Q_WS_X11
    Window sibling = mTargetWin;
    Window dw, parent = None, *wins;

    do {
        unsigned int nwins = 0;

        // We must use the target window's parent as our sibling.
        // Is there a faster way to get parent window than XQueryTree?
        if( XQueryTree( QX11Info::display(), sibling, &dw, &parent, &wins, &nwins ) ) {
            if( nwins ) {
                XFree(wins);
            }
        }

        if( parent != None && parent != dw ) {
            sibling = parent;
        }
    } while( parent != None && parent != dw );

    // Set animation's stacking order to be above the window manager's
    // decoration of target window.
    XWindowChanges values;
    values.sibling = sibling;
    values.stack_mode = Above;
    XConfigureWindow( QX11Info::display(), mAmor->winId(), CWSibling | CWStackMode, &values);
#endif
}
Example #4
0
// scan for windows and add them to the list of managed clients
// from dwm.c
void scan(void) {
    unsigned int num;
    Window d1, d2, *cl, *wins = NULL;
    unsigned long cl_count;
    XWindowAttributes wa;

    ewmh_get_original_client_list(&cl, &cl_count);
    if (XQueryTree(g_display, g_root, &d1, &d2, &wins, &num)) {
        for (int i = 0; i < num; i++) {
            if(!XGetWindowAttributes(g_display, wins[i], &wa)
            || wa.override_redirect || XGetTransientForHint(g_display, wins[i], &d1))
                continue;
            // only manage mapped windows.. no strange wins like:
            //      luakit/dbus/(ncurses-)vim
            // but manage it if it was in the ewmh property _NET_CLIENT_LIST by
            // the previous window manager
            // TODO: what would dwm do?
            if (is_window_mapped(g_display, wins[i])
                || 0 <= array_find(cl, cl_count, sizeof(Window), wins+i)) {
                manage_client(wins[i]);
                XMapWindow(g_display, wins[i]);
            }
        }
        if(wins)
            XFree(wins);
    }
    // ensure every original client is managed again
    for (int i = 0; i < cl_count; i++) {
        if (get_client_from_window(cl[i])) continue;
        if (!XGetWindowAttributes(g_display, cl[i], &wa)
            || wa.override_redirect
            || XGetTransientForHint(g_display, cl[i], &d1))
        {
            continue;
        }
        XReparentWindow(g_display, cl[i], g_root, 0,0);
        manage_client(cl[i]);
    }
}
static Window getCurrentWindow(JNIEnv *env, jlong display_ptr, jlong window_ptr) {
	Display *disp = (Display *)(intptr_t)display_ptr;

	Window parent = (Window)window_ptr;
	Window win, root;

	Window *children;
	unsigned int nchildren;

	do {
		win = parent;

		if (XQueryTree(disp, win, &root, &parent, &children, &nchildren) == 0) {
			throwException(env, "XQueryTree failed");
			return 0;
		}

		if (children != NULL) XFree(children);
	} while (parent != root);

	return win;
}
Example #6
0
// Tries to find the real window that corresponds to a top-level window (the actual window without window manager decorations).
// Returns None if it can't find the window (probably because the window is not handled by the window manager).
// Based on the xprop source code (http://cgit.freedesktop.org/xorg/app/xprop/tree/clientwin.c).
static Window X11FindRealWindow(Display* display, Window window) {

	// is this the real window?
	Atom actual_type;
	int actual_format;
	unsigned long items, bytes_left;
	unsigned char *data = NULL;
	XGetWindowProperty(display, window, XInternAtom(display, "WM_STATE", true),
					   0, 0, false, AnyPropertyType, &actual_type, &actual_format, &items, &bytes_left, &data);
	if(data != NULL)
		XFree(data);
	if(actual_type != None)
		return window;

	// get the child windows
	Window root, parent, *childs;
	unsigned int childcount;
	if(!XQueryTree(display, window, &root, &parent, &childs, &childcount)) {
		return None;
	}

	// recursively call this function for all childs
	Window real_window = None;
	for(unsigned int i = childcount; i > 0; ) {
		--i;
		Window w = X11FindRealWindow(display, childs[i]);
		if(w != None) {
			real_window = w;
			break;
		}
	}

	// free child window list
	if(childs != NULL)
		XFree(childs);

	return real_window;

}
Example #7
0
static Window
find_toplevel_window (Window xid)
{
  Window root, parent, *children;
  guint nchildren;

  do
    {
      if (XQueryTree (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xid, &root,
		      &parent, &children, &nchildren) == 0)
	{
	  g_warning ("Couldn't find window manager window");
	  return None;
	}

      if (root == parent)
	return xid;

      xid = parent;
    }
  while (TRUE);
}
Example #8
0
static bool verifyTree(const T &order,
                       Window **childrenp, unsigned *nchildrenp)
{
    Window foo;
    Window *children;
    unsigned nchildren;

    Q_ASSERT(Dpy != NULL);
    if (!XQueryTree(Dpy, fakeRoot, &foo, &foo, &children, &nchildren))
        qFatal("XQueryTree() failed");

    if (!verifyOrder(order, children, nchildren))
        return false;

    if (childrenp) {
        *childrenp  = children;
        *nchildrenp = nchildren;
    } else
        XFree(children);

    return true;
}
void
JXDockWindowTask::Perform
	(
	const Time	delta,
	Time*		maxSleepTime
	)
{
	*maxSleepTime = 100;

	if (itsWindow == NULL)
		{
		delete this;
		return;
		}

	// Gnome takes its own sweet time catching some event related to
	// reparenting, and this leaves the window on the desktop!

	Window root, parent, *childList;
	unsigned int childCount;
	if (!XQueryTree(*(itsWindow->GetDisplay()), itsWindow->GetXWindow(),
					&root, &parent, &childList, &childCount))
		{
		delete this;
		return;
		}
	XFree(childList);

	if (parent == itsParent)
		{
		delete this;
		return;
		}
	else // if (parent == root)
		{
		XReparentWindow(*(itsWindow->GetDisplay()), itsWindow->GetXWindow(),
						itsParent, itsPoint.x, itsPoint.y);
		}
}
Example #10
0
static Window
get_desktop_window (Window the_window)
{
  Atom prop, type, prop2;
  int format;
  unsigned long length, after;
  unsigned char *data;
  unsigned int nchildren;
  Window w, root, *children, parent;

  prop = XInternAtom(GDK_DISPLAY(), "_XROOTPMAP_ID", True);
  prop2 = XInternAtom(GDK_DISPLAY(), "_XROOTCOLOR_PIXEL", True);

  if (prop == None && prop2 == None)
    return None;

  for (w = the_window; w; w = parent) {
    if ((XQueryTree(GDK_DISPLAY(), w, &root, &parent, &children, &nchildren)) == False)
      return None;

    if (nchildren)
      XFree(children);

    if (prop != None) {
      XGetWindowProperty(GDK_DISPLAY(), w, prop, 0L, 1L, False, AnyPropertyType,
       &type, &format, &length, &after, &data);
    } else if (prop2 != None) {
      XGetWindowProperty(GDK_DISPLAY(), w, prop2, 0L, 1L, False, AnyPropertyType,
       &type, &format, &length, &after, &data);
    } else  {
      continue;
    }

    if (type != None) {
      return w;
    }
  }
  return None;
}
Example #11
0
Window FindWindowByClass(Window parent, const char* className)
{
	Window root, *children;
	unsigned int nchildren;
	Atom WM_CLASS = XInternAtom(XDisplay, "WM_CLASS",0);
	XQueryTree(XDisplay, parent, &root, &parent,&children, &nchildren);
	Window ret=0;
	for(unsigned int c=0; c<nchildren; c++)
	{
		Window win=children[c];

		unsigned long bytes_after, len;
		unsigned char *value;
		int format;
		Atom actual_type;
		if(XGetWindowProperty(XDisplay,win,WM_CLASS,0,1024,False,XA_STRING, &actual_type, &format,
						   &len,&bytes_after,&value)==Success)
		{
			if(value!=0)
			{
				value[len-1]=0;


				if(strcmp((char*)value, className) == 0)
				{
					XFree(value);
					ret=win;
					break;
				}
				XFree(value);
			}
			ret=FindWindowByClass(win, className);
			if(ret!=0)
				break;
		}
	}
	XFree(children);
	return ret;
}
Example #12
0
static Window local_find_window (Display *display, Window root, char *name)
{
    Window parent;
    Window *children;
    unsigned int num_children = 0;
    unsigned i;
    int status = 0;
    XTextProperty tex_prop;
    char **list_return = NULL;
    int count_return = 0;
    status = XGetWMName(display, root, &tex_prop);
    if(status && tex_prop.value && tex_prop.nitems)
    {
        status = XmbTextPropertyToTextList (display, &tex_prop, &list_return, &count_return);
        if(status >= Success && count_return > 0 && *list_return)
        {
                if( !strcmp(name, (char*) strdup (*list_return)) ){
                    XFreeStringList(list_return);
                    return root;
                }
        }
    }
    status = XQueryTree (display, root, &root, &parent, &children, &num_children);
    if (status == 0 || num_children == 0)
    {
        XFree ((char*) children);
        return (Window)NULL;
    }
    for (i=0; i < num_children; i++)
    {
        Window result = local_find_window (display, children[i], name);
        if(result){
            XFree ((char*) children);
        return result;
        }
    }
    XFree ((char*) children);
    return (Window)NULL;
}
Example #13
0
void wxTopLevelWindowMotif::DoGetPosition(int *x, int *y) const
{
    Widget top = (Widget) GetTopWidget();
    Window parent_window = XtWindow((Widget) top),
        next_parent   = XtWindow((Widget) top),
        root          = RootWindowOfScreen(XtScreen((Widget) top));

    // search for the parent that is child of ROOT, because the WM may
    // reparent twice and notify only the next parent (like FVWM)
    while (next_parent != root) {
        Window *theChildren; unsigned int n;
        parent_window = next_parent;
        XQueryTree(XtDisplay((Widget) top), parent_window, &root,
            &next_parent, &theChildren, &n);
        XFree(theChildren); // not needed
    }
    int xx, yy; unsigned int dummy;
    XGetGeometry(XtDisplay((Widget) top), parent_window, &root,
        &xx, &yy, &dummy, &dummy, &dummy, &dummy);
    if (x) *x = xx;
    if (y) *y = yy;
}
static int 
win_exists(Window win, Window top)
{
  Window *children, dummy;
  unsigned int nchildren;
  int i, w = 0;
  
  if (top == win) return 1;
  
  if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
    return 0;
  
  for (i=0; i<nchildren; i++) 
    {
      w = win_exists(win, children[i]);
      if (w) break;
    }

  if (children) XFree ((char *)children);
  return(w);

}
Example #15
0
Window
XRemoteClient::CheckChildren(Window aWindow)
{
  Window root, parent;
  Window *children;
  unsigned int nchildren;
  unsigned int i;
  Atom type = None;
  int format;
  unsigned long nitems, after;
  unsigned char *data;
  Window retval = None;
  
  if (!XQueryTree(mDisplay, aWindow, &root, &parent, &children,
		  &nchildren))
    return None;
  
  // scan the list first before recursing into the list of windows
  // which can get quite deep.
  for (i=0; !retval && (i < nchildren); i++) {
    XGetWindowProperty(mDisplay, children[i], mMozWMStateAtom,
		       0, 0, False, AnyPropertyType, &type, &format,
		       &nitems, &after, &data);
    if (type) {
      XFree(data);
      retval = children[i];
    }
  }

  // otherwise recurse into the list
  for (i=0; !retval && (i < nchildren); i++) {
    retval = CheckChildren(children[i]);
  }

  if (children)
    XFree((char *)children);

  return retval;
}
Example #16
0
static
void getWindowsRecursive( std::vector<QRect> *windows, Window w,
              int rx = 0, int ry = 0, int depth = 0 )
{
    XWindowAttributes atts;
    XGetWindowAttributes( QX11Info::display(), w, &atts );

    if ( atts.map_state == IsViewable &&
         atts.width >= minSize && atts.height >= minSize ) {
        int x = 0, y = 0;
        if ( depth ) {
            x = atts.x + rx;
            y = atts.y + ry;
        }

        QRect r( x, y, atts.width, atts.height );
        if ( std::find( windows->begin(), windows->end(), r ) == windows->end() ) {
            windows->push_back( r );
        }

        Window root, parent;
        Window* children;
        unsigned int nchildren;

        if( XQueryTree( QX11Info::display(), w, &root, &parent, &children, &nchildren ) != 0 ) {
                for( unsigned int i = 0; i < nchildren; ++i ) {
                    getWindowsRecursive( windows, children[ i ], x, y, depth + 1 );
                }

                if( children != NULL ) {
                    XFree( children );
                }
        }
    }

    if ( depth == 0 ) {
        std::sort( windows->begin(), windows->end() );
    }
}
Example #17
0
bool
CXWindowsScreenSaver::findXScreenSaver()
{
	// do nothing if we've already got the xscreensaver window
	if (m_xscreensaver == None) {
		// find top-level window xscreensaver window
		Window root = DefaultRootWindow(m_display);
		Window rw, pw, *cw;
		unsigned int nc;
		if (XQueryTree(m_display, root, &rw, &pw, &cw, &nc)) {
			for (unsigned int i = 0; i < nc; ++i) {
				if (isXScreenSaver(cw[i])) {
					setXScreenSaver(cw[i]);
					break;
				}
			}
			XFree(cw);
		}
	}

	return (m_xscreensaver != None);
}
Example #18
0
void window_manage_all(void)
{
	guint i, j, nchild;
	Window w, *children;
	XWMHints *wmhints;
	XWindowAttributes attrib;
	if(!XQueryTree(t_display, DefaultRootWindow(t_display), &w, &w, &children, &nchild)) {
		wm_debug("XQueryTree failed in window_manage_all");
		nchild = 0;
	}
	for(i = 0; i < nchild; i++) {
		if(children[i] == None)
			continue;
		wmhints = XGetWMHints(t_display, children[i]);
		if(wmhints) {
			if((wmhints->flags & IconWindowHint) && (wmhints->icon_window != children[i]))
				for(j = 0; j < nchild; j++)
					if(children[j] == wmhints->icon_window) {
						children[j] = None;
						break;
					}
			XFree(wmhints);
		}
	}
	for(i = 0; i < nchild; ++i) {
		if(children[i] == None)
			continue;
		if(window_find(children[i]))
			continue;
		if(XGetWindowAttributes(t_display, children[i], &attrib)) {
			if(attrib.map_state == IsUnmapped);
			else
				window_manage(children[i]);
		}
	}
	if(children)
		XFree(children);
}
Example #19
0
void client_message_handler(XEvent local_event, Display *display){
	printf("----------ClientMessage\n");
	printf("\tMessage: %s\n", XGetAtomName(display,local_event.xclient.message_type));
	printf("\tFormat: %d\n", local_event.xclient.format); 
	Atom *atoms = (Atom *)local_event.xclient.data.l;
	int i =0;
	for(i=0; i<=5; i++){
		printf("\t\tData %d: %s\n", i, XGetAtomName(display, atoms[i]));
	}
	int nchild;
	Window *child_windows;
	Window parent_window;
	Window root_window;
	XQueryTree(display, local_event.xclient.window, &root_window, &parent_window, &child_windows, &nchild);
	printf("\tNumber of childs: %d\n", nchild);
	XEvent new_event;
	Atom new_atom = XInternAtom(display, "_NET_WM_STATE_ABOVE", True);
	if(new_atom == False){
		printf("\tDoes not exist _NET_WM_STATE");
	}
	printf("Creating new Atom client Message, with value: %d\n", ClientMessage);
	new_event.xclient.type = ClientMessage;
	new_event.xclient.serial = 0;
	new_event.xclient.send_event = 1;
	new_event.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False);
	new_event.xclient.display = local_event.xclient.display;
	new_event.xclient.window = local_event.xclient.window;
	new_event.xclient.format = 32;
	new_event.xclient.data.l[0] = 1;
	new_event.xclient.data.l[1] = new_atom;
	new_event.xclient.data.l[2] = 0;
	new_event.xclient.data.l[3] = 0;
	new_event.xclient.data.l[4] = 0;
	unsigned long mask = 1 << 20 /* SubstructureRedirectMask */ | 1 << 19 /* SubstructureNotifyMask */ ;
	XSendEvent(display, InputFocus, False, mask, &new_event);
	XFlush(new_event.xclient.display);
	printf("-------------\n");
}
Example #20
0
static void
socket_unrealize_cb(GtkWidget *widget, gpointer data)
{
    // Unmap and reparent any child windows that GDK does not yet know about.
    // (See bug 540114 comment 10.)
    GdkWindow* socket_window =  gtk_widget_get_window(widget);
    GdkDisplay* gdkDisplay = gdk_display_get_default();
    Display* display = GDK_DISPLAY_XDISPLAY(gdkDisplay);

    // Ignore X errors that may happen if windows get destroyed (possibly
    // requested by the plugin) between XQueryTree and when we operate on them.
    gdk_error_trap_push();

    Window root, parent;
    Window* children;
    unsigned int nchildren;
    if (!XQueryTree(display, gdk_x11_window_get_xid(socket_window),
                    &root, &parent, &children, &nchildren))
        return;

    for (unsigned int i = 0; i < nchildren; ++i) {
        Window child = children[i];
        if (!gdk_x11_window_lookup_for_display(gdkDisplay, child)) {
            // This window is not known to GDK.
            XUnmapWindow(display, child);
            XReparentWindow(display, child, DefaultRootWindow(display), 0, 0);
        }
    }

    if (children) XFree(children);

    mozilla::FinishX(display);
#if (MOZ_WIDGET_GTK == 3)
    gdk_error_trap_pop_ignored();
#else
    gdk_error_trap_pop();
#endif
}
Example #21
0
MetaStackTracker *
meta_stack_tracker_new (MetaScreen *screen)
{
  MetaStackTracker *tracker;
  Window ignored1, ignored2;
  Window *children;
  guint n_children;

  tracker = g_new0 (MetaStackTracker, 1);
  tracker->screen = screen;

  tracker->server_serial = XNextRequest (screen->display->xdisplay);

  XQueryTree (screen->display->xdisplay,
              screen->xroot,
              &ignored1, &ignored2, &children, &n_children);
  tracker->server_stack = copy_stack (children, n_children);
  XFree (children);

  tracker->queued_requests = g_queue_new ();

  return tracker;
}
Example #22
0
// scan for windows and add them to the list of managed clients
void scan(void) {
    unsigned int i, num;
    Window d1, d2, *wins = NULL;
    XWindowAttributes wa;

    if(XQueryTree(gDisplay, gRoot, &d1, &d2, &wins, &num)) {
        for(i = 0; i < num; i++) {
            if(!XGetWindowAttributes(gDisplay, wins[i], &wa)
            || wa.override_redirect || XGetTransientForHint(gDisplay, wins[i], &d1))
                continue;
            if (wa.map_state == IsViewable)
                manage_client(wins[i]);
        }
        for(i = 0; i < num; i++){ // now the transients
           if(!XGetWindowAttributes(gDisplay, wins[i], &wa))
              continue;
           if(XGetTransientForHint(gDisplay, wins[i], &d1)
              && (wa.map_state == IsViewable))
              manage_client(wins[i]);
        }
        if(wins) XFree(wins);
    }
}
Example #23
0
/*
* Window_With_Name: routine to locate a window with a given name on a display.
* If no window with the given name is found, 0 is returned.
* If more than one window has the given name, the first
* one found will be returned. Only top and its subwindows
* are looked at. Normally, top should be the RootWindow.
*/
Window
Window_With_Name(Display *display, Window top, const char *name)
{
Window *children, dummy;
unsigned int nchildren;
unsigned int i;
Window w=0;
char *window_name;

if (XFetchName(display, top, &window_name) && !strcmp(window_name, name))
return(top);

if (!XQueryTree(display, top, &dummy, &dummy, &children, &nchildren))
return(0);

for (i=0; i<nchildren; i++) {
w = Window_With_Name(display, children[i], name);
if (w)
break;
}
if (children) XFree ((char *)children);
return(w);
}
Example #24
0
/** Returns an int of 0 if the Window 'win' exists or an int representing
 * the error it ran into.
 * win the Window to be searched for.
 * If the function failed to open an X display or could not find a Window 'win',
 * then it will return the correct error code for window-not-found.
 * If 'win' was found, then the function will return 0.
 */
int window_exists(Window win) {

	Display *display;

	if (!(display = XOpenDisplay(0))) { return ERR_COULDNT_OPEN_X_DISPLAY; }

	int screen = DefaultScreen(display);
	Window root_win = RootWindow(display, screen);
	Window root_ret, parent_ret, *child_ret;
	unsigned int number_children;
	XQueryTree(display, root_win, &root_ret, &parent_ret, &child_ret, \
		&number_children);

	for (int i = 0; i < number_children; i++) {
		Window temp = *(child_ret + i);
		/* 'win' exists, return 0 */
		if (temp == win) {
			return 0;
		}
	}

	return ERR_WIN_NOT_FOUND;
}
Example #25
0
static Window
find_toplevel_window (Display *display,
                      Window   xid)
{
  Window  root, parent, *children;
  guint   nchildren;

  do
    {
      if (XQueryTree (display, xid,
                      &root, &parent, &children, &nchildren) == 0)
        {
          g_warning ("Couldn't find window manager window");
          return 0;
        }

      if (root == parent)
        return xid;

      xid = parent;
    }
  while (TRUE);
}
Example #26
0
void walkWindowTree ( Window w, void (*func) ( Window, void* ), void* data )
{
	Window* children;
	Window dummy;
	unsigned int n;
	unsigned int i;

	func ( w, data );

	XQueryTree ( dp, w, &dummy, &dummy, &children, &n );

	if ( n == 0 || children == NULL )
		return;

	for ( i = 0; i < n; ++i )
	{
		walkWindowTree ( children[i], func, data );
	}

	XFree ( children );

	return;
}
Example #27
0
void XPos(Window win, int *x, int *y)
{
	XWindowAttributes attr;
	int xx = 0, yy = 0;
	unsigned int ntree;
	Window root;
	Window *tree;
	Window nwin = win;
	XGetWindowAttributes(dsp, win, &attr);
	xx = attr.x;
	yy = attr.y;
	do {
		win = nwin;
		XQueryTree(dsp, win, &root, &nwin, &tree, &ntree);
		XFree(tree);
		XGetWindowAttributes(dsp, nwin, &attr);
		xx += attr.x;
		yy += attr.y;
	}
	while (nwin != RootWindow(dsp, 0));
	*x = xx;
	*y = yy;
}
Example #28
0
void xUIwindows(Window topwin, int *anz, Window *win, int maxwins, Boolean build, Boolean *ok)
{
	extern Display *display;

	Window		root_return, parent_return, *children;
	int			i, j, anzchildren;

	XQueryTree(display, topwin, &root_return, &parent_return, &children, (unsigned int *)&anzchildren);
	if (anzchildren > 0) {
		for (i=0; i<anzchildren; i++) {
			xUIwindows(children[i], anz, win, maxwins, build, ok);
		}
		XFree((void *)children);
	}
	if (build) {
		if (*anz < maxwins)
			win[*anz] = topwin;
	}
	(*anz)++;
	if (*anz <= maxwins) *ok=TRUE;
	else                 *ok=FALSE;
	return;
}
Example #29
0
void foreign_callback_call(const char *id) {
	fl_open_display();

	init_foreign_callback_atom_once();

	::Window dummy, root, *children = 0;
	unsigned int nchildren, id_hash;

	root = RootWindow(fl_display, fl_screen);
	XQueryTree(fl_display, root, &dummy, &dummy, &children, &nchildren);
	if(!nchildren)
		return;

	id_hash = str_hash(id);

	for(unsigned int i = 0; i < nchildren; i++) {
		if(children[i] != root)
			send_client_message(children[i], _XA_EDELIB_FOREIGN_CALLBACK, id_hash);
	}

	XFree(children);
	XSync(fl_display, False);
}
Example #30
0
File: xim.c Project: adaptee/fcitx
pid_t XimFindApplicationPid(FcitxXimFrontend* xim, Window w) {
    if (w == DefaultRootWindow(xim->display))
        return 0;

    Atom actual_type;
    int actual_format;
    unsigned long nitems;
    unsigned long bytes;
    unsigned char* prop;
    int status = XGetWindowProperty(
        xim->display, w, XInternAtom(xim->display, "_NET_WM_PID", True), 0,
        1024L, False, AnyPropertyType, &actual_type, &actual_format, &nitems,
        &bytes, (unsigned char**) &prop);
    if (status != 0) {
        if (status == BadRequest)
            return 0;
        return 0;
    }
    if (!prop) {
        Window parent;
        Window root;
        Window* children = NULL;
        unsigned int sz = 0;
        status = XQueryTree(xim->display, w, &root, &parent, &children, &sz);
        if (status != 0) {
            if (status == BadRequest)
                return 0;
            return 0;
        }
        if (children)
            XFree(children);
        return XimFindApplicationPid(xim, parent);
    } else {
        // TODO: is this portable?
        return prop[1] * 256 + prop[0];
    }
}