Esempio n. 1
0
unsigned char *
get_window_title(void)
{
#ifdef HAVE_X11
	/* Following code is stolen from our beloved vim. */
	unsigned char *winid;
	Display *display;
	Window window, root, parent, *children;
	XTextProperty text_prop;
	Status status;
	unsigned int num_children;
	unsigned char *ret = NULL;

	if (!is_xterm())
		return NULL;

	winid = getenv("WINDOWID");
	if (!winid)
		return NULL;
	window = (Window) atol(winid);
	if (!window)
		return NULL;

	display = XOpenDisplay(NULL);
	if (!display)
		return NULL;

	/* If WINDOWID is bad, we don't want X to abort us. */
	x_error = 0;
	XSetErrorHandler((int (*)(Display *, XErrorEvent *)) catch_x_error);

	status = XGetWMName(display, window, &text_prop);
	/* status = XGetWMIconName(x11_display, x11_window, &text_prop); */
	while (!x_error && (!status || !text_prop.value)) {
		if (!XQueryTree(display, window, &root, &parent, &children, &num_children))
			break;
		if (children)
			XFree((void *) children);
		if (parent == root || parent == 0)
			break;
		window = parent;
		status = XGetWMName(display, window, &text_prop);
	}

	if (!x_error && status && text_prop.value) {
		ret = stracpy(text_prop.value);
		XFree(text_prop.value);
	}

	XCloseDisplay(display);

	return ret;
#else
	/* At least reset the window title to a blank one. */
	return stracpy("");
#endif
}
Esempio n. 2
0
/* XFetchName Wrapper */
Bool wFetchName(Display *dpy, Window win, char **winname)
{
	XTextProperty text_prop;
	char **list;
	int num;

	if (XGetWMName(dpy, win, &text_prop)) {
		if (text_prop.value && text_prop.nitems > 0) {
			if (text_prop.encoding == XA_STRING) {
				*winname = wstrdup((char *)text_prop.value);
				XFree(text_prop.value);
			} else {
				text_prop.nitems = strlen((char *)text_prop.value);
				if (XmbTextPropertyToTextList(dpy, &text_prop, &list, &num) >=
				    Success && num > 0 && *list) {
					XFree(text_prop.value);
					*winname = wstrdup(*list);
					XFreeStringList(list);
				} else {
					*winname = wstrdup((char *)text_prop.value);
					XFree(text_prop.value);
				}
			}
		} else {
			/* the title is set, but it was set to none */
			*winname = wstrdup("");
		}
		return True;
	} else {
		/* the hint is probably not set */
		*winname = NULL;

		return False;
	}
}
Esempio n. 3
0
// ######################################################################
Window AutomateXWin::XWindowByName(Display *display, const Window rootwin, const char *name)
{
  unsigned int num_children;
  Window *children, child, window;
  XTextProperty windowname;

  if(XGetWMName(display, rootwin, &windowname) != 0)
  {
    LINFO("Window='%s'\n", (const char *)windowname.value);
    if(!strcmp((const char *)windowname.value, name))
      return rootwin;
  }

  window = (Window) NULL;

  if(XQueryTree(display, rootwin, &child, &child, &children, &num_children))
  {
    unsigned i;
    for(i=0; i < num_children; ++i)
    {
      /* Search each child and their children. */
      window = XWindowByName(display, children[i], name);
      if(window != (Window) NULL)
        break;
    }
    if (children != (Window *)NULL)
      XFree((void *)children);
  }
  return window;
}
Esempio n. 4
0
/*
getWinTitle:
   This function gets the window title for a given Window handle.

Input:
   dsp: The current XDisplay.
   win: The window handle that you want the title for.

Output:
   Returns a char* containing the window's title.
 
*/
char *getWinTitle(Display *dsp, Window win) {
   Status status;
   XTextProperty prop;
   char *err = "";
   char **list = NULL;
   int count;
   int ret;

   status = XGetWMName(dsp, win, &prop);
   ret = XmbTextPropertyToTextList(dsp, &prop, &list, &count);
   if (ret == Success || ret > 0 && list != NULL) {
      int i = 0;
      
      for (i = 0; i < count; i++) {
         if (list[i] == NULL) {
            err = "null";
         } else {
            err = (char*)malloc(strlen(list[i])+1);
            err = strcpy(err, list[i]);
         }
      }

      if (list != NULL) {
         XFreeStringList(list);
      }
   } 

   return err;
}
	std::string getWindowName(Window win)
	{
		Atom netWmName = XInternAtom(disp(), "_NET_WM_NAME", false);
		int n;
		char **list = 0;
		XTextProperty tp;
		std::string res = "unknown";

		XGetTextProperty(disp(), win, &tp, netWmName);

		if (!tp.nitems)
			XGetWMName(disp(), win, &tp);

		if (!tp.nitems)
			return "error";

		if (tp.encoding == XA_STRING) {
			res = (char*)tp.value;
		} else {
			int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
					&n);

			if (ret >= Success && n > 0 && *list) {
				res = *list;
				XFreeStringList(list);
			}
		}

		XFree(tp.value);

		return res;
	}
Esempio n. 6
0
// Thanks zcodes!
char *get_window_name(Window win)
{
    XTextProperty text_property;
    Status status = XGetWMName(server.display, win, &text_property);
    if (!status || !text_property.value || !text_property.nitems) {
        return strdup("");
    }

    char **name_list;
    int count;
    status = Xutf8TextPropertyToTextList(server.display, &text_property, &name_list, &count);
    if (status < Success || !count) {
        XFree(text_property.value);
        return strdup("");
    }

    if (!name_list[0]) {
        XFreeStringList(name_list);
        XFree(text_property.value);
        return strdup("");
    }

    char *result = strdup(name_list[0]);
    XFreeStringList(name_list);
    XFree(text_property.value);
    return result;
}
Esempio n. 7
0
static Window get_daemon_window(Display *dpy)
{
  Window win, root_win;
  XTextProperty wname;
  Atom type;
  int fmt;
  unsigned long nitems, bytes_after;
  unsigned char *prop;

  root_win = DefaultRootWindow(dpy);

  XGetWindowProperty(dpy, root_win, command_event, 0, 1, False, AnyPropertyType, &type, &fmt, &nitems, &bytes_after, &prop);
  if(!prop) {
    return 0;
  }

  win = *(Window*)prop;
  XFree(prop);

  if(!XGetWMName(dpy, win, &wname) || strcmp("Magellan Window", (char*)wname.value) != 0) {
    return 0;
  }

  return win;
}
Esempio n. 8
0
void
updatetitle(Client *c) {
    char **list = NULL;
    int n;
    XTextProperty name;

    name.nitems = 0;
    c->name[0] = 0;
    XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
    if(!name.nitems)
        XGetWMName(dpy, c->win, &name);
    if(!name.nitems)
        return;
    if(name.encoding == XA_STRING)
        strncpy(c->name, (char *)name.value, sizeof c->name);
    else {
        if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
                && n > 0 && *list)
        {
            strncpy(c->name, *list, sizeof c->name);
            XFreeStringList(list);
        }
    }
    XFree(name.value);
}
Esempio n. 9
0
char *ICCCM::get_title(Frame *f)
{
    XTextProperty xtp;
    char *title = 0;

    if(XGetWMName(fl_display, f->window(), &xtp))
    {
        if(xtp.encoding == XA_STRING) {
            title = strdup((const char*)xtp.value);
        } else {
#if HAVE_X11_UTF_TEXT_PROP
            int items;
            char **list=0;
            Status s;
            s = Xutf8TextPropertyToTextList(fl_display, &xtp, &list, &items);
            if((s == Success) && (items > 0)) {
                title = strdup((const char *)*list);
            } else
                title = strdup((const char *)xtp.value);
            if(list) XFreeStringList(list);
#else
            title = strdup((const char*)xtp.value);
#endif
        }
        XFree(xtp.value);
    }
    return title;
}
Esempio n. 10
0
static void
GetWindowName (Display *pDisplay, Window iWin, char **ppName)
{
  int			nResult, nNum;
  char			**ppList;
  XTextProperty		xtpName;
  
#if CYGMULTIWINDOW_DEBUG
  ErrorF ("GetWindowName\n");
#endif

  /* Intialize ppName to NULL */
  *ppName = NULL;

  /* Try to get --- */
  nResult = XGetWMName (pDisplay, iWin, &xtpName);
  if (!nResult || !xtpName.value || !xtpName.nitems)
    {
      ErrorF ("GetWindowName - XGetWMName failed.  No name.\n");
      return;
    }
  
  /* */
  if (xtpName.encoding == XA_STRING)
    {
      /* */
      if (xtpName.value)
	{
	  *ppName = strdup ((char*)xtpName.value);
	  XFree (xtpName.value);
	}

#if CYGMULTIWINDOW_DEBUG
      ErrorF ("XA_STRING %s\n", *ppName);
#endif
    }
  else
    {
      XmbTextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum);

      /* */
      if (nNum && *ppList)
	{
	  XFree (xtpName.value);
	  *ppName = strdup (*ppList);
	  XFreeStringList (ppList);
	}

#if CYGMULTIWINDOW_DEBUG
      ErrorF ("%s %s\n", XGetAtomName (pDisplay, xtpName.encoding), *ppName);
#endif
    }


#if CYGMULTIWINDOW_DEBUG
  ErrorF ("-GetWindowName\n");
#endif
}
Esempio n. 11
0
void query(Display *xdpy, int window, int level) {
  int i, j;
  Window *children, dummy;
  unsigned int nchildren;

  if (!XQueryTree(xdpy, window, &dummy, &dummy, &children, &nchildren))
    return;

  for (i = 0; i < nchildren; i++) {
    Window w = children[i];
    XWindowAttributes attr;
    XTextProperty tp;
    XClassHint classhint;
    char *name;

    XGetWindowAttributes(xdpy, w, &attr);
    XGetWMName(xdpy, w, &tp);

    if (tp.nitems > 0) {
      indent(level - 1);
      printf("+ %d (%dx%d@%d,%d) [%s]\n", w, 
             attr.x, attr.y, attr.width, attr.height,
             (attr.map_state == IsViewable ? "Visible" : "Hidden"));

      int count = 0;
      char **list = NULL;
      int ret;
      ret = XmbTextPropertyToTextList(xdpy, &tp, &list, &count);
      indent(level);
      for (j = 0; j < count; j++)
        printf("%s", list[j]);
      XFreeStringList(list);
    } else {
      //printf("(!) %s\n", tp.value);
      query(xdpy, w, level);
      continue;
    }

    if (XGetClassHint(xdpy, w, &classhint)) {
      printf("\n");
      indent(level);
      if (classhint.res_name) {
        printf("\"%s\" ", classhint.res_name);
        XFree(classhint.res_name);
      }
      if (classhint.res_class) {
        printf("\"%s\" ", classhint.res_class);
        XFree(classhint.res_class);
      }
    }
    printf("\n");

    query(xdpy, w, level+1);
  }

}
Esempio n. 12
0
/* text_prop_return is really XTextProperty*, but to avoid extra includes, we'll use void* */
Status
count_xgetwmname (const char *fname, int line, Display * display, Window w, void *text_prop_return)
{
	Status        val;
	XTextProperty *prop = text_prop_return;

	val = XGetWMName (display, w, prop);
	if (val && prop->nitems)
		count_alloc (fname, line, (void *)prop->value, prop->nitems * prop->format / 8, C_XMEM | C_XGETWMNAME);
	return val;
}
Esempio n. 13
0
EAPI char *
ecore_x_icccm_title_get(Ecore_X_Window win)
{
   XTextProperty xprop;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   xprop.value = NULL;
   if (XGetWMName(_ecore_x_disp, win, &xprop) >= Success)
     {
        if (_ecore_xlib_sync) ecore_x_sync();
        if (xprop.value)
          {
             char **list = NULL;
             char *t = NULL;
             int num = 0;
             int ret;

             if (xprop.encoding == ECORE_X_ATOM_UTF8_STRING)
               t = strdup((char *)xprop.value);
             else
               {
                  /* convert to utf8 */
#ifdef X_HAVE_UTF8_STRING
                  ret = Xutf8TextPropertyToTextList(_ecore_x_disp, &xprop,
                                                    &list, &num);
#else /* ifdef X_HAVE_UTF8_STRING */
                  ret = XmbTextPropertyToTextList(_ecore_x_disp, &xprop,
                                                  &list, &num);
#endif /* ifdef X_HAVE_UTF8_STRING */
                  if (_ecore_xlib_sync) ecore_x_sync();

                  if ((ret == XLocaleNotSupported) ||
                      (ret == XNoMemory) || (ret == XConverterNotFound))
                    t = strdup((char *)xprop.value);
                  else if ((ret >= Success) && (num > 0))
                    t = strdup(list[0]);

                  if (list)
                    XFreeStringList(list);
               }

             if (xprop.value)
               XFree(xprop.value);

             return t;
          }
     }
   else
     {
        if (_ecore_xlib_sync) ecore_x_sync();
     }

   return NULL;
}
Esempio n. 14
0
// i got the idea for this from taskbar-plugin of LXPanel - so credits fly out :)
QString XfitMan::getWindowTitle(Window _wid) const
{
    QString name = "";
    //first try the modern net-wm ones
    unsigned long length;
    unsigned char *data = nullptr;
    
    Atom utf8Atom = atom("UTF8_STRING");

    if (getWindowProperty(_wid, atom("_NET_WM_VISIBLE_NAME"), utf8Atom, &length, &data))
    {
        name = QString::fromUtf8((char*) data);
        XFree(data);

    }

    if (name.isEmpty())
    {
        if (getWindowProperty(_wid, atom("_NET_WM_NAME"), utf8Atom, &length, &data))
        {
            name = QString::fromUtf8((char*) data);
            XFree(data);
        }
    }

    if (name.isEmpty())
    {
        if (getWindowProperty(_wid, atom("XA_WM_NAME"), XA_STRING, &length, &data))
        {
            name = (char*) data;
            XFree(data);
        }
    }

    if (name.isEmpty())
    {
        Status ok = XFetchName(QX11Info::display(), _wid, (char**) &data);
        name = QString((char*) data);
        if (0 != ok) XFree(data);
    }

    if (name.isEmpty())
    {
        XTextProperty prop;
        if (XGetWMName(QX11Info::display(), _wid, &prop))
        {
            name = QString::fromUtf8((char*) prop.value);
            XFree(prop.value);
        }
    }

    return name;
}
Esempio n. 15
0
void list_windows()
{
	XTextProperty name_info;
	int i;

	if (display == NULL) return;

	for (i=0; i<top_level_window_list.length; i++)
	{
		XGetWMName(display, top_level_window_list.set[i], &name_info);

		if (name_info.value != NULL)
			printf("  0x%.8lx %s\n", (unsigned long) top_level_window_list.set[i], (char *) name_info.value);
	}
}
Esempio n. 16
0
static PetscErrorCode PetscDrawSetTitle_X(PetscDraw draw,const char title[])
{
  PetscDraw_X    *win = (PetscDraw_X*)draw->data;
  XTextProperty  prop;
  PetscErrorCode ierr;
  size_t         len;

  PetscFunctionBegin;
  if (win->win) {
    XGetWMName(win->disp,win->win,&prop);
    XFree((void*)prop.value);
    prop.value  = (unsigned char *)title;
    ierr        = PetscStrlen(title,&len);CHKERRQ(ierr);
    prop.nitems = (long) len;
    XSetWMName(win->disp,win->win,&prop);
  }
  PetscFunctionReturn(0);
}
Esempio n. 17
0
static int query_x11(void)
{
	Display *dpy;
	Window win, root_win;
	XTextProperty wname;
	Atom type, command_event;
	int fmt;
	unsigned long nitems, bytes_after;
	unsigned char *prop;

	if(!(dpy = XOpenDisplay(0))) {
		return 0;
	}
	root_win = DefaultRootWindow(dpy);

	if((command_event = XInternAtom(dpy, "CommandEvent", True)) == None) {
		XCloseDisplay(dpy);
		return 0;
	}

	XGetWindowProperty(dpy, root_win, command_event, 0, 1, False, AnyPropertyType,
			&type, &fmt, &nitems, &bytes_after, &prop);
	if(!prop) {
		XCloseDisplay(dpy);
		return 0;
	}

	win = *(Window*)prop;
	XFree(prop);

	if(!XGetWMName(dpy, win, &wname) || strcmp("Magellan Window", (char*)wname.value) != 0) {
		XCloseDisplay(dpy);
		return 0;
	}
	XCloseDisplay(dpy);

	/* found a magellan window, still it might belong to the 3dxsrv driver */
	if(get_daemon_pid() == -1) {
		return 0;
	}

	/* this could still mean that the daemon crashed and left behind the pidfile... */
	return 1;	/* ... but wtf */
}
Esempio n. 18
0
void systray_property_notify(TrayWindow *traywin, XEvent *e)
{
	Atom at = e->xproperty.atom;
	if (at == server.atom.WM_NAME) {
		free(traywin->name);

		XTextProperty xname;
		if (XGetWMName(server.display, traywin->win, &xname)) {
			traywin->name = strdup((char *)xname.value);
			XFree(xname.value);
		} else {
			traywin->name = strdup("");
		}

		if (systray.sort == SYSTRAY_SORT_ASCENDING || systray.sort == SYSTRAY_SORT_DESCENDING) {
			systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows);
			// print_icons();
		}
	}
}
Esempio n. 19
0
void FindPixel (char *windowName, int x, int y, Display *display, Window rootWindow)
{
	Window parent;
	Window *children;
	Window *child;
	XImage *image;
	XWindowAttributes winAttr;
	XColor color;
	XTextProperty wmName;

	unsigned int noOfChildren;
	unsigned long pixel;
	int status;
	int i, red, green, blue;
	char **list;

	status = XGetWMName (display, rootWindow, &wmName);

	if ((status) && (wmName.value) && (wmName.nitems)) {
		if (strcmp(windowName, wmName.value) == 0) {
			XGetWindowAttributes(display, rootWindow, &winAttr);
			image = XGetImage(display, rootWindow, 0, 0, winAttr.width, winAttr.height, XAllPlanes(), ZPixmap);
			color.pixel = XGetPixel(image, x, y);
			XQueryColor(display, XDefaultColormap(display, XDefaultScreen(display)), &color);
			red = floor(color.red * 0.003891051);
			green = floor(color.green * 0.003891051);
			blue = floor(color.blue * 0.003891051);

			printf("%i %i %i\n", red, green, blue);
		}
	}
	
	
	status = XQueryTree (display, rootWindow, &rootWindow, &parent, &children, &noOfChildren);
	
	for (i=0; i < noOfChildren; i++) {
		FindPixel (windowName, x, y, display, children[i]);
	}
	
	XFree ((char*) children);
}
Esempio n. 20
0
static void
GetWindowName (Display *pDisplay, Window iWin, char **ppName)
{
  int			nResult, nNum;
  char			**ppList;
  XTextProperty		xtpName;
  
#if CYGMULTIWINDOW_DEBUG
  ErrorF ("GetWindowName\n");
#endif

  /* Intialize ppName to NULL */
  *ppName = NULL;

  /* Try to get --- */
  nResult = XGetWMName (pDisplay, iWin, &xtpName);
  if (!nResult || !xtpName.value || !xtpName.nitems)
    {
#if CYGMULTIWINDOW_DEBUG
      ErrorF ("GetWindowName - XGetWMName failed.  No name.\n");
#endif
      return;
    }
  
  /* */
  if (xtpName.encoding == XA_STRING)
    {
      /* */
      if (xtpName.value)
	{
	  int size = xtpName.nitems * (xtpName.format >> 3);
	  *ppName = malloc(size + 1);
	  strncpy(*ppName, xtpName.value, size);
	  (*ppName)[size] = 0;
	  XFree (xtpName.value);
	}

#if CYGMULTIWINDOW_DEBUG
      ErrorF ("GetWindowName - XA_STRING %s\n", *ppName);
#endif
    }
Esempio n. 21
0
// ######################################################################
void AutomateXWin::XListWindows(Display *display, const Window rootwin)
{
  unsigned int num_children;
  Window *children, child;
  XTextProperty windowname;

  if(XGetWMName(display, rootwin, &windowname) != 0)
    LINFO("  '%s'\n", (const char *)windowname.value);

  if(XQueryTree(display, rootwin, &child, &child, &children, &num_children))
  {
    unsigned i;
    for(i=0; i < num_children; ++i)
    {
      /* Search each child and their children. */
      XListWindows(display, children[i]);
    }
    if (children != (Window *)NULL)
      XFree((void *)children);
  }
}
Esempio n. 22
0
static int _xdo_window_match_title(const xdo_t *xdo, Window window, regex_t *re) {
  int i;
  int count = 0;
  char **list = NULL;
  XTextProperty tp;

  XGetWMName(xdo->xdpy, window, &tp);
  if (tp.nitems > 0) {
    XmbTextPropertyToTextList(xdo->xdpy, &tp, &list, &count);
    for (i = 0; i < count; i++) {
      //printf("%d: title '%s'\n", window, list[i]);
      if (regexec(re, list[i], 0, NULL, 0) == 0) {
        XFreeStringList(list);
        XFree(tp.value);
        return True;
      }
    }
  }
  XFreeStringList(list);
  XFree(tp.value);
  return False;
}
Esempio n. 23
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;
}
Esempio n. 24
0
	std::string getWindowAtom(Window win, const char *atom)
	{
		Atom netWmName = XInternAtom(disp(), atom, false);
		int n;
		char **list = 0;
		XTextProperty tp;
		std::string res = "unknown";

		XGetTextProperty(disp(), win, &tp, netWmName);

		if (!tp.nitems)
			XGetWMName(disp(), win, &tp);

		if (!tp.nitems)
			return "error";

		if (tp.encoding == XA_STRING) {
			res = (char*)tp.value;
		} else {
			int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
					&n);

			if (ret >= Success && n > 0 && *list) {
				res = *list;
				XFreeStringList(list);
			}
		}

		char *conv = nullptr;
		if (os_mbs_to_utf8_ptr(res.c_str(), 0, &conv)) 
			res = conv;
		bfree(conv);

		XFree(tp.value);

		return res;
	}
/* support for findWindowWithLabel */
static inline int
windowHasLabel(Window w, char *label)
{
	XTextProperty win_text;
	int hasLabel;

	if (!XGetWMName(stDisplay, w, &win_text)) {
		char *win_name;
		if (!XFetchName(stDisplay, w, &win_name))
			return 0;
		hasLabel = !strcmp(label, win_name);
		(void)XFree(win_name);
		return hasLabel;
	}
	/* If there are multiple items and we need to support that see use of
	 * XmbTextPropertyToTextList in xwininfo.
	 * If UTF8 is required see stringprep_locale_to_utf8 & libidn.
	 */
	if (win_text.nitems <= 0)
		return 0;
	hasLabel = !strcmp(label, win_text.value);
	(void)XFree(win_text.value);
	return hasLabel;
}
Esempio n. 26
0
//
// Add a new window to the stack
//
WindowStack *push_stack(Display *d, Window window)
{
	WindowStack *sitem = NULL;
	
	// see if this window is already in the stack
	printf("see if window is already in stack\n");
	WindowStack *iter = stack;
	while (iter != NULL) {
		if (iter->window == window) { // we can do this as windows are just unsigned longs
			break;
		}
		iter = iter->next;
	}
	if (iter != NULL) { // if we haven't reached NULL, the break was called above and we have an existing window!
		
		// update existing stack item
		printf("update existing item\n");
		sitem = iter;
		
	} else {
		
		// create a new stack item
		printf("new window to add to stack\n");
		sitem = (WindowStack *)malloc(sizeof(WindowStack));
		sitem->window = window;
		sitem->display = d;
		if (stack != NULL) {
			sitem->next = stack; // add to stack
		}
		stack = sitem; // add item to top of stack	
	}
	
	if (sitem == NULL) {
		printf("sitem was NULL when unexpected\n");
		return stack;
	}
	
	// get/update screenshot
	printf("get window properties\n");
	XWindowAttributes a;
	if (XGetWindowAttributes(d, window, &a)) {
		
		// release old one if present
		//printf("release old screenshot if present\n");
		//if (sitem->screenshot != NULL) XDestroyImage(sitem->screenshot);
		
		// create new one
		//printf("create new screenshot\n");
		//sitem->screenshot = XGetImage(d, window, 0, 0, a.width, a.height, AllPlanes, ZPixmap);
		
	}
	
	// get window title
	printf("get window title\n");
	XTextProperty prop_title;
	int i=0;
	if ( !XGetWMName(d, window, &prop_title) ) {
		printf("title retrieved from Xlib\n");
		sitem->title = (char *)prop_title.value;
	} else {
		printf("titled created from scratch\n");
		char *title = (char *)malloc(sizeof(char) * 11); // upto 99 unnamed windows
		sprintf(title, "Untitled%d", ++i);
		sitem->title = title;
	}
	
	return stack; 
}
Esempio n. 27
0
/* 
      XBSetWindowLabel - Sets new label in open window.

  Input Parameters:
.  window - Window to set label for
.  label  - Label to give window
  */
void XBSetWindowLabel( XBWindow *XBwin, char *label ){
	XTextProperty prop;
	XGetWMName(XBwin->disp,XBwin->win,&prop);
	prop.value = (unsigned char *)label; prop.nitems = (long) strlen(label);
	XSetWMName(XBwin->disp,XBwin->win,&prop);
}
Esempio n. 28
0
Window	hci_window_query (
    Display	*display,
    Window	window,
    char	*name
)
{
    Window	root_ret;
    Window	parent_ret;
    Window	*child_ret;
    unsigned int	num_child;
    int	i;
    int	status;
    XTextProperty	property;
    Window	ret;
    char	buf [32];

    ret = 0;

    XQueryTree (display,
                window,
                &root_ret,
                &parent_ret,
                &child_ret,
                &num_child);

    /*	For each branch in window tree recursively call this function	*
     *	until the end of the branch is reached.  If a match is found	*
     *	then the return value will be > 0.				*/

    for (i=0; i<num_child; i++) {

        ret = hci_window_query (display, child_ret [i], name);

        if (ret > 0) {

            XFree (child_ret);
            return (ret);

        }
    }

    /*	Get the propetries of the window.				*/

    status = XGetWMName (display,
                         window,
                         &property);

    /*	If we were able to get the properties, then we want to see if	*
     *	the first part of the window name matches the name passed to	*
     *	this function.  If a match is found then if the configuration	*
     *	is FAA redundant we need to also match the channel annotation	*
     *	added to the end of the window name.				*/

    if (status != 0) {

        if (!strncmp ((char *) property.value, name, strlen (name))) {

            if (HCI_get_system() == HCI_FAA_SYSTEM) {

                sprintf (buf,"FAA:%d",
                         ORPGRED_channel_num (ORPGRED_MY_CHANNEL));

                if (strstr ((char *) property.value,buf) != NULL) {

                    ret = window;

                }

            } else {

                ret = window;

            }
        }

        XFree (property.value);

    }

    XFree (child_ret);

    return (ret);
}
Esempio n. 29
0
Client *createclient(Window w)
{
  extern void checkstyle(Client *c);

  XWindowAttributes attr;
  Client *c;

  if(w==0) return 0;
  if(!XFindContext(dpy, w, client_context, (XPointer*)&c)) return c;

  XGetWindowAttributes(dpy, w, &attr);

  c = (Client *)calloc(1, sizeof(Client));
  c->scr = scr;
  c->window = w;
  c->parent = scr->root;
  c->old_bw = attr.border_width;
  c->next = clients;
  c->state = WithdrawnState;
  c->gravity = NorthWestGravity;
  c->reparenting = 0;
  XSelectInput(dpy, c->window, PropertyChangeMask);
#ifdef USE_FONTSETS
  {
    XTextProperty prop;
    c->title = NULL;
    if(XGetWMName(dpy, c->window, &prop) && prop.value) {
      char **list;
      int n;
      if(XmbTextPropertyToTextList(dpy, &prop, &list, &n) >= Success) {
	if(n > 0)
	  c->title = strdup(list[0]);
	XFreeStringList(list);
      }
      XFree(prop.value);
    }
  }
#else
  XGetWMName(dpy, c->window, &c->title);
#endif
  c->style = NULL;
  checkstyle(c);
  checksizehints(c);
  c->zoomx=0;
  c->zoomy=scr->bh;
  if(c->sizehints.width_inc) {
    c->zoomw=scr->width-c->sizehints.base_width-22;
    c->zoomw-=c->zoomw%c->sizehints.width_inc;
    c->zoomw+=c->sizehints.base_width;
    if(c->zoomw>c->sizehints.max_width)
      c->zoomw=c->sizehints.max_width;
    if(c->zoomw<c->sizehints.min_width)
      c->zoomw=c->sizehints.min_width;
  } else
    c->zoomw=attr.width;
  if(c->sizehints.height_inc) {
    c->zoomh=scr->height-c->sizehints.base_height-scr->bh-c->zoomy-2;
    c->zoomh-=c->zoomh%c->sizehints.height_inc;
    c->zoomh+=c->sizehints.base_height;
    if(c->zoomh>c->sizehints.max_height)
      c->zoomh=c->sizehints.max_height;
    if(c->zoomh<c->sizehints.min_height)
      c->zoomh=c->sizehints.min_height;
  } else
    c->zoomh=attr.height;
  XSaveContext(dpy, w, client_context, (XPointer)c);
  return clients = c;
}
Window doTreeWalk(Window wind,bool thisdesktop)
{
	Window			root,parent;
	Window			*children;
	Window			thewin;
	unsigned int	n_children;
	int				i;
	unsigned long	winid;
	char			*wname;
	unsigned long	desktop;
	void			*ptr=NULL;
	unsigned long	count=32;
	Atom			rtype;
	int				rfmt;
	unsigned long	rafter;
	unsigned long	n=0;
	XTextProperty	textpropreturn;

	if (!XQueryTree(mainwind->display,wind,&root,&parent,&children,&n_children))
		return None;

	if (!children)
		return None;

	/* Check each child for WM_STATE and other validity */
	thewin=None;
	wname=NULL;
	winid=-1;
	desktop=-1;
	for (int j=n_children-1; j>=0; j--)
		{
			if((thisdesktop==true) && (isVisible(mainwind->display, children[j])==false))
				{
					children[j]=None; /* Don't bother descending into this one */
					continue;
				}
			if (!hasProp(mainwind->display, children[j],WM_STATE))
				continue;

			if (!hasWindowProp(children[j],NET_WM_WINDOW_TYPE_NORMAL,NET_WM_WINDOW_TYPE))
				continue;

			/* Got one */
			thewin=children[j];
			winid=children[j];
			XFetchName(mainwind->display,children[j],&wname);
			if(wname==NULL)
				{
					if(XGetWMName(mainwind->display,children[j],&textpropreturn)!=0)
						wname=strdup((char*)textpropreturn.value);
					else
						{
							printError("Can't determine window name...");
							wname=strdup("Untitled...");
						}
				}
		}

	thewin=None;
	/* No children matched, now descend into each child */
	for (i=(int) n_children - 1; i >= 0; i--)
		{
			if (children[i]==None)
				continue;
			if (isHidden(children[i])==true)
				continue;
			
			thewin=doTreeWalk(children[i],thisdesktop);
			if (thewin != None)
				break;
		}

	if(winid!=-1)
		{
			ptr=NULL;
			count=32;
			n=0;
			if(XGetWindowProperty(mainwind->display,winid,NET_WM_DESKTOP,0L,count,false,XA_CARDINAL,&rtype,&rfmt,&n,&rafter,(unsigned char **)&ptr)==Success)
				desktop=(long)(*(char*)ptr);

			if(thisdesktop==true)
				{
					windowDeskList[windowDeskListCnt].bc=NULL;
					windowDeskList[windowDeskListCnt].subMenus=NULL;
					windowDeskList[windowDeskListCnt].subMenuCnt=desktop;
					windowDeskList[windowDeskListCnt].useIcon=false;
					windowDeskList[windowDeskListCnt].label=strdup(wname);
					windowDeskList[windowDeskListCnt].userData=(void*)winid;
					windowDeskListCnt++;
				}
			else
				{
					windowList[windowListCnt].bc=NULL;
					windowList[windowListCnt].subMenus=NULL;
					windowList[windowListCnt].subMenuCnt=desktop;
					windowList[windowListCnt].useIcon=false;
					windowList[windowListCnt].label=strdup(wname);
					windowList[windowListCnt].userData=(void*)winid;
					windowListCnt++;
				}
		}

	if(wname!=NULL)
		XFree(wname);

	XFree(children);
	return thewin;

}