static bool register_cm(Display* dpy) { Window w; Atom a; a = XInternAtom (dpy, "_NET_WM_CM_S0", False); w = XGetSelectionOwner (dpy, a); if (w != None) { XTextProperty tp; char **strs; int count; Atom winNameAtom = XInternAtom (dpy, "_NET_WM_NAME", False); if (!XGetTextProperty (dpy, w, &tp, winNameAtom) && !XGetTextProperty (dpy, w, &tp, XA_WM_NAME)) { fprintf (stderr, "Another composite manager is already running (0x%lx)\n", (unsigned long) w); return false; } if (XmbTextPropertyToTextList (dpy, &tp, &strs, &count) == Success) { fprintf (stderr, "Another composite manager is already running (%s)\n", strs[0]); XFreeStringList (strs); } XFree (tp.value); return false; } w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None, None); Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL, NULL); XSetSelectionOwner (dpy, a, w, 0); return true; }
/** Returns 1 if the dmxScreen and the display in \a name are on the * same display, or 0 otherwise. We can't just compare the display * names because there can be multiple synonyms for the same display, * some of which cannot be determined without accessing the display * itself (e.g., domain aliases or machines with multiple NICs). */ int dmxPropertySameDisplay(DMXScreenInfo * dmxScreen, const char *name) { Display *dpy0 = dmxScreen->beDisplay; Atom atom0; XTextProperty tp0; Display *dpy1 = NULL; Atom atom1; XTextProperty tp1; int retval = 0; if (!dpy0) return 0; tp0.nitems = 0; tp1.nitems = 0; if ((atom0 = XInternAtom(dpy0, DMX_ATOMNAME, True)) == None) { dmxLog(dmxWarning, "No atom on %s\n", dmxScreen->name); return 0; } if (!XGetTextProperty(dpy0, RootWindow(dpy0, 0), &tp0, atom0) || !tp0.nitems) { dmxLog(dmxWarning, "No text property on %s\n", dmxScreen->name); return 0; } if (!(dpy1 = XOpenDisplay(name))) { dmxLog(dmxWarning, "Cannot open %s\n", name); goto cleanup; } atom1 = XInternAtom(dpy1, DMX_ATOMNAME, True); if (atom1 == None) { dmxLog(dmxDebug, "No atom on %s\n", name); goto cleanup; } if (!XGetTextProperty(dpy1, RootWindow(dpy1, 0), &tp1, atom1) || !tp1.nitems) { dmxLog(dmxDebug, "No text property on %s\n", name); goto cleanup; } if (!strcmp((char *) tp0.value, (char *) tp1.value)) retval = 1; cleanup: if (tp0.nitems) XFree(tp0.value); if (tp1.nitems) XFree(tp1.value); if (dpy1) XCloseDisplay(dpy1); return retval; }
/** Returns NULL if this is the only Xdmx window on the display. * Otherwise, returns a pointer to the dmxScreen of the other windows on * the display. */ static DMXScreenInfo * dmxPropertyCheckOtherWindows(DMXScreenInfo * dmxScreen, Atom atom) { Display *dpy = dmxScreen->beDisplay; const unsigned char *id = dmxPropertyIdentifier(); XTextProperty tproot; XTextProperty tp; const char *pt; int (*dmxOldHandler) (Display *, XErrorEvent *); if (!dpy) return NULL; if (!XGetTextProperty(dpy, RootWindow(dpy, 0), &tproot, atom) || !tproot.nitems) return 0; /* Ignore BadWindow errors for this * routine because the window id stored * in the property might be old */ dmxOldHandler = XSetErrorHandler(dmxPropertyErrorHandler); for (pt = (const char *) tproot.value; pt && *pt; pt = pt ? pt + 1 : NULL) { if ((pt = strchr(pt, ','))) { Window win = strtol(pt + 1, NULL, 10); if (XGetTextProperty(dpy, win, &tp, atom) && tp.nitems) { dmxLog(dmxDebug, "On %s/%lu: %s\n", dmxScreen->name, win, tp.value); if (!strncmp((char *) tp.value, (char *) id, strlen((char *) id))) { int idx; if (!(pt = strchr((char *) tp.value, ','))) continue; idx = strtol(pt + 1, NULL, 10); if (idx < 0 || idx >= dmxNumScreens) continue; if (dmxScreens[idx].scrnWin != win) continue; XSetErrorHandler(dmxOldHandler); return &dmxScreens[idx]; } XFree(tp.value); } } } XSetErrorHandler(dmxOldHandler); XFree(tproot.value); return 0; }
WMenu *wAppMenuGet(WScreen * scr, Window window) { XTextProperty text_prop; int count, i; char **slist; WMenu *menu; if (!XGetTextProperty(dpy, window, &text_prop, w_global.atom.wmaker.menu)) { return NULL; } if (!XTextPropertyToStringList(&text_prop, &slist, &count) || count < 1) { XFree(text_prop.value); return NULL; } XFree(text_prop.value); if (strcmp(slist[0], "WMMenu 0") != 0) { wwarning("appmenu: unknown version of WMMenu in window %lx: %s", window, slist[0]); XFreeStringList(slist); return NULL; } i = 1; menu = parseMenuCommand(scr, window, slist, count, &i); if (menu) menu->parent = NULL; XFreeStringList(slist); return menu; }
// retrieve a text property from a window // technically we could use window_get_prop(), but this is better for character set support char* window_get_text_prop ( Display *display, Window w, Atom atom ) { XTextProperty prop; char *res = NULL; char **list = NULL; int count; if ( XGetTextProperty ( display, w, &prop, atom ) && prop.value && prop.nitems ) { if ( prop.encoding == XA_STRING ) { size_t l = strlen ( ( char *) prop.value ) + 1; res = g_malloc ( l ); // make clang-check happy. if ( res ) { g_strlcpy ( res, ( char * ) prop.value, l ); } } else if ( Xutf8TextPropertyToTextList ( display, &prop, &list, &count ) >= Success && count > 0 && *list ) { size_t l = strlen ( *list ) + 1; res = g_malloc ( l ); // make clang-check happy. if ( res ) { g_strlcpy ( res, *list, l ); } XFreeStringList ( list ); } } if ( prop.value ) { XFree ( prop.value ); } return res; }
int xu_getstrprop(Window win, Atom atm, char **text) { XTextProperty prop; char **list; int nitems = 0; *text = NULL; XGetTextProperty(X_Dpy, win, &prop, atm); if (!prop.nitems) return (0); if (Xutf8TextPropertyToTextList(X_Dpy, &prop, &list, &nitems) == Success && nitems > 0 && *list) { if (nitems > 1) { XTextProperty prop2; if (Xutf8TextListToTextProperty(X_Dpy, list, nitems, XUTF8StringStyle, &prop2) == Success) { *text = xstrdup((const char *)prop2.value); XFree(prop2.value); } } else { *text = xstrdup(*list); } XFreeStringList(list); } XFree(prop.value); return (nitems); }
static Window search_children (Display *display, Window w, string s) { Window root, parent, win; Window *children; unsigned nchildren; XTextProperty textP; /* Test this window. */ if (XGetTextProperty (display, w, &textP, foserver_identity_atom) && textP.encoding == XA_STRING && textP.encoding == XA_STRING && textP.format == 8 && textP.nitems != 0 && STREQ ((string) textP.value, s)) { XFree ((char *) textP.value); return w; /* This is the correct window. */ } /* OK, we found nothing. Recursively try the children. */ if (XQueryTree (display, w, &root, &parent, &children, &nchildren) == 0) FATAL ("limn: XQueryTree failed on parent"); for (; nchildren > 0; nchildren--) if (win = search_children (display, children[nchildren-1], s)) { XFree ((char *) children); return win; } XFree ((char *) children); return None; /* We didn't find anything. */ }
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); }
static char * titleinfoGetTextProperty (CompDisplay *d, Window id, Atom atom) { XTextProperty text; char *retval = NULL; text.nitems = 0; if (XGetTextProperty (d->display, id, &text, atom)) { if (text.value) { retval = malloc (sizeof (char) * (text.nitems + 1)); if (retval) { strncpy (retval, (char *) text.value, text.nitems); retval[text.nitems] = 0; } XFree (text.value); } } return retval; }
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; }
CompString PrivateTextScreen::getTextProperty (Window id, Atom atom) { XTextProperty text; CompString retval; text.nitems = 0; if (XGetTextProperty (screen->dpy (), id, &text, atom)) { if (text.value) { char valueString[text.nitems + 1]; strncpy (valueString, (char *) text.value, text.nitems); valueString[text.nitems] = 0; retval = valueString; XFree (text.value); } } return retval; }
std::string getWindowCommand(Window win) { Atom xi = XInternAtom(disp(), "WM_COMMAND", false); int n; char **list = 0; XTextProperty tp; std::string res = "error"; XGetTextProperty(disp(), win, &tp, xi); if (!tp.nitems) return std::string(); 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; }
Status count_xgettextproperty(const char *fname, int line, Display * display, Window w, XTextProperty *trg, Atom property) { Status val; val = XGetTextProperty(display,w,trg,property); if (val && trg->value ) count_alloc (fname, line, (void *)(trg->value), strlen((char*)trg->value)+1, C_XMEM | C_XGETTEXTPROPERTY ); return val; }
/** * @brief Get the first string in a UTF-8 string property on a window. */ char * wm_wid_get_prop_utf8(session_t *ps, Window wid, Atom prop) { XTextProperty text_prop = { }; char *ret = NULL; if (XGetTextProperty(ps->dpy, wid, &text_prop, prop)) { char **strlst = NULL; int cstr = 0; Xutf8TextPropertyToTextList(ps->dpy, &text_prop, &strlst, &cstr); if (cstr) ret = mstrdup(strlst[0]); if (strlst) XFreeStringList(strlst); } sxfree(text_prop.value); return ret; }
bool hc_next_hook(HCConnection* con, int* argc, char** argv[]) { if (!hc_hook_window_connect(con)) { return false; } // get window to listen at Window win = con->hook_window; // listen on window XEvent next_event; bool received_hook = false; while (!received_hook) { XNextEvent(con->display, &next_event); if (next_event.type == DestroyNotify) { if (next_event.xdestroywindow.window == win) { // hook window was destroyed // so quit idling return false; } } if (next_event.type != PropertyNotify) { fprintf(stderr, "Warning: got other event than PropertyNotify\n"); continue; } XPropertyEvent* pe = &next_event.xproperty; if (pe->state == PropertyDelete) { // just ignore property delete events continue; } if (pe->window != win) { fprintf(stderr, "Warning: expected event from window %u", (unsigned int)win); fprintf(stderr, " but got something from %u\n", (unsigned int)pe->window); continue; } XTextProperty text_prop; XGetTextProperty(con->display, win, &text_prop, pe->atom); char** list_return; int count; if (Success != Xutf8TextPropertyToTextList(con->display, &text_prop, &list_return, &count)) { XFree(text_prop.value); return false; } *argc = count; *argv = argv_duplicate(count, list_return); received_hook = true; // cleanup XFreeStringList(list_return); XFree(text_prop.value); } return true; }
void Navit::_searchWindow(Window startWinID) { Window rootWindow; Window parent; Window * ch; unsigned int chCount; XTextProperty data; int j; if (!startWinID) { startWinID = QX11Info::appRootWindow(); } if (!XQueryTree(QX11Info::display(), startWinID, &rootWindow, &parent, &ch, &chCount)) { qDebug() << "XQueryTree: failed!"; return; } for(unsigned int i = 0; i < chCount; i++) { if (XGetTextProperty(QX11Info::display(), ch[i], &data, XA_WM_CLASS)) { if (QString((char *)data.value) == "navit") { /* Dodaj okno do listy, jeśli go tam nie ma */ for(j = 0; j < _navitWindows.count(); j++) { if (_navitWindows.at(j) == ch[i]) break; } if (j >= _navitWindows.count()) { _navitWindows.append(ch[i]); } if (_navitWindows.count() == _expectWindows) { _searchTimer->stop(); /* Ustawiamy widocznosc okna */ if (_isVisible) show(); else hide(); return; } } } _searchWindow(ch[i]); } XFree(ch); }
void propertynotify(XEvent *ev) { XPropertyEvent *e = &ev->xproperty; if (e->window != wshow) return; if (e->atom != COM_ATOM) return; char **strs = NULL; int n; XTextProperty text; XGetTextProperty(dpy, wshow, &text, COM_ATOM); if (!text.nitems) return; if (text.encoding == XA_STRING) command( (char *) text.value); else if (XmbTextPropertyToTextList(dpy, &text, &strs, &n) >= Success) { command( (char *) *strs); XFreeStringList(strs); } XFree(text.value); }
static gboolean has_xsmp_support (Window window) { XTextProperty tp; gboolean has_it = FALSE; if (XGetTextProperty (gdk_display, window, &tp, _XA_SM_CLIENT_ID)) { if (tp.encoding == XA_STRING && tp.format == 8 && tp.nitems != 0) has_it = TRUE; if (tp.value != NULL) XFree ((char *) tp.value); } return has_it; }
int getprop_textlist(Window *w, const char *name, char **ret[]) { XTextProperty prop; char **list; int n; *ret = nil; n = 0; XGetTextProperty(display, w->xid, &prop, xatom(name)); if(prop.nitems > 0) { if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success) *ret = list; XFree(prop.value); } return n; }
int dwbremote_get_property(Display *dpy, Window win, Atom atom, char ***list, int *count) { int result = True; XTextProperty prop; if (!XGetTextProperty(dpy, win, &prop, atom)) { return False; } if (Xutf8TextPropertyToTextList(dpy, &prop, list, count) != Success) { result = False; } XFree(prop.value); return result; }
/** * Get a window string property. * @param win The window * @param type The property * @return Window string property of a window. String must be free'd when done. */ EAPI char * ecore_x_window_prop_string_get(Ecore_X_Window win, Ecore_X_Atom type) { XTextProperty xtp; char *str = NULL; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (win == 0) win = DefaultRootWindow(_ecore_x_disp); if (XGetTextProperty(_ecore_x_disp, win, &xtp, type)) { int items; char **list = NULL; Status s; if (_ecore_xlib_sync) ecore_x_sync(); if (xtp.encoding == ECORE_X_ATOM_UTF8_STRING) str = strdup((char *)xtp.value); else { #ifdef X_HAVE_UTF8_STRING s = Xutf8TextPropertyToTextList(_ecore_x_disp, &xtp, &list, &items); #else /* ifdef X_HAVE_UTF8_STRING */ s = XmbTextPropertyToTextList(_ecore_x_disp, &xtp, &list, &items); #endif /* ifdef X_HAVE_UTF8_STRING */ if (_ecore_xlib_sync) ecore_x_sync(); if ((s == XLocaleNotSupported) || (s == XNoMemory) || (s == XConverterNotFound)) str = strdup((char *)xtp.value); else if ((s >= Success) && (items > 0)) str = strdup(list[0]); if (list) XFreeStringList(list); } XFree(xtp.value); } return str; }
static char* sessionGetTextProperty (CompDisplay *d, Window id, Atom atom) { XTextProperty text; char *retval = NULL; text.nitems = 0; if (XGetTextProperty (d->display, id, &text, atom)) { if (text.value) { retval = strndup ((char *)text.value,text.nitems); XFree (text.value); } } return retval; }
void UpdateIconName(UltimateContext *uc) { XTextProperty prop; char **stringlist; int count; if(uc->title.iconname) free(uc->title.iconname); if(!XGetTextProperty(disp, uc->win, &prop, XA_WM_ICON_NAME)) { uc->title.iconname = NULL; return; } if(XTextPropertyToStringList(&prop, &stringlist, &count) && (count > 0)){ uc->title.iconname = calloc(strlen(stringlist[0]) + 1, sizeof(char)); if(uc->title.iconname) strcpy(uc->title.iconname, stringlist[0]); XFreeStringList(stringlist); } else uc->title.iconname = NULL; XFree(prop.value); DBG(fprintf(TheScreen.errout,"Window icon Name: %s\n",uc->title.iconname);) }
char * get_textproperty(Window win, Atom atom) { XTextProperty text_prop; char *retval; ENTER; if (XGetTextProperty(gdk_helper_display(), win, &text_prop, atom)) { DBG("format=%d enc=%d nitems=%d value=%s \n", text_prop.format, text_prop.encoding, text_prop.nitems, text_prop.value); retval = text_property_to_utf8 (&text_prop); if (text_prop.nitems > 0) XFree (text_prop.value); RET(retval); } RET(NULL); }
/* title_get_text_property */ static int _title_get_text_property(Title * title, Window window, Atom property, char ** ret) { int res; XTextProperty text; GdkAtom atom; int cnt; char ** list; int i; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(title, window, %lu)\n", __func__, property); #endif gdk_error_trap_push(); res = XGetTextProperty(GDK_DISPLAY_XDISPLAY(title->display), window, &text, property); if(gdk_error_trap_pop() != 0 || res == 0) return 1; atom = gdk_x11_xatom_to_atom(text.encoding); #if GTK_CHECK_VERSION(2, 24, 0) cnt = gdk_x11_display_text_property_to_text_list(title->display, atom, text.format, text.value, text.nitems, &list); #else cnt = gdk_text_property_to_utf8_list(atom, text.format, text.value, text.nitems, &list); #endif if(cnt > 0) { *ret = list[0]; for(i = 1; i < cnt; i++) g_free(list[i]); g_free(list); } else *ret = NULL; if(text.value != NULL) XFree(text.value); return 0; }
// retrieve a text property from a window // technically we could use window_get_prop(), but this is better for character set support char* window_get_text_prop(Window w, Atom atom) { XTextProperty prop; char *res = NULL; char **list = NULL; int count; if (XGetTextProperty(display, w, &prop, atom) && prop.value && prop.nitems) { if (prop.encoding == XA_STRING) { res = allocate(strlen((char*)prop.value)+1); strcpy(res, (char*)prop.value); } else if (XmbTextPropertyToTextList(display, &prop, &list, &count) >= Success && count > 0 && *list) { res = allocate(strlen(*list)+1); strcpy(res, *list); XFreeStringList(list); } } if (prop.value) XFree(prop.value); return res; }
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; }
// inspired by dwm's gettextprop() GString* window_property_to_g_string(Display* dpy, Window window, Atom atom) { GString* result = NULL; char** list = NULL; int n = 0; XTextProperty prop; if (0 == XGetTextProperty(dpy, window, &prop, atom)) { return NULL; } // convert text property to a gstring if (prop.encoding == XA_STRING || prop.encoding == XInternAtom(dpy, "UTF8_STRING", False)) { result = g_string_new((char*)prop.value); } else { if (XmbTextPropertyToTextList(dpy, &prop, &list, &n) >= Success && n > 0 && *list) { result = g_string_new(*list); XFreeStringList(list); } } XFree(prop.value); return result; }
QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist) { QString title; Atom type; int format; unsigned long nitems; unsigned long after; unsigned char* data = nullptr; // the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, false, m_atomUtf8String, &type, &format, &nitems, &after, &data); if ((retVal == 0) && data) { title = QString::fromUtf8(reinterpret_cast<char*>(data)); } else { XTextProperty textProp; retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName); if ((retVal != 0) && textProp.value) { char** textList = nullptr; int count; if (textProp.encoding == m_atomUtf8String) { title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value)); } else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0) && textList && (count > 0)) { title = QString::fromLocal8Bit(textList[0]); } else if (textProp.encoding == m_atomString) { title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value)); } if (textList) { XFreeStringList(textList); } } if (textProp.value) { XFree(textProp.value); } } if (data) { XFree(data); } if (useBlacklist && !title.isEmpty()) { if (window == m_rootWindow) { return QString(); } QString className = windowClassName(window); if (m_classBlacklist.contains(className)) { return QString(); } QList<Window> keepassxWindows = widgetsToX11Windows(QApplication::topLevelWidgets()); if (keepassxWindows.contains(window)) { return QString(); } } return title; }
/** Returns 0 if this is the only Xdmx session on the display; 1 * otherwise. */ static int dmxPropertyCheckOtherServers(DMXScreenInfo * dmxScreen, Atom atom) { Display *dpy = dmxScreen->beDisplay; XTextProperty tp; XTextProperty tproot; const char *pt; int retcode = 0; char **list = NULL; int count = 0; int i; int (*dmxOldHandler) (Display *, XErrorEvent *); if (!dpy) return 0; if (!XGetTextProperty(dpy, RootWindow(dpy, 0), &tproot, atom) || !tproot.nitems) return 0; /* Ignore BadWindow errors for this * routine because the window id stored * in the property might be old */ dmxOldHandler = XSetErrorHandler(dmxPropertyErrorHandler); for (pt = (const char *) tproot.value; pt && *pt; pt = pt ? pt + 1 : NULL) { if ((pt = strchr(pt, ','))) { Window win = strtol(pt + 1, NULL, 10); if (XGetTextProperty(dpy, win, &tp, atom) && tp.nitems) { if (!strncmp((char *) tp.value, DMX_IDENT, strlen(DMX_IDENT))) { int flag = 0; for (i = 0; i < count; i++) if (!strcmp(list[i], (char *) tp.value)) { ++flag; break; } if (flag) continue; ++retcode; dmxLogOutputWarning(dmxScreen, "%s also running on %s\n", tp.value, dmxScreen->name); list = realloc(list, ++count * sizeof(*list)); list[count - 1] = malloc(tp.nitems + 2); strncpy(list[count - 1], (char *) tp.value, tp.nitems + 1); } XFree(tp.value); } } } XSetErrorHandler(dmxOldHandler); for (i = 0; i < count; i++) free(list[i]); free(list); XFree(tproot.value); if (!retcode) dmxLogOutput(dmxScreen, "No Xdmx server running on backend\n"); return retcode; }