/** * Get a window name & class. * @param win The window * @param n The name string * @param c The class string * * Get a window name * class */ EAPI void ecore_x_icccm_name_class_get(Ecore_X_Window win, char **n, char **c) { XClassHint xch; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (n) *n = NULL; if (c) *c = NULL; xch.res_name = NULL; xch.res_class = NULL; if (XGetClassHint(_ecore_x_disp, win, &xch)) { if (n) if (xch.res_name) *n = strdup(xch.res_name); if (c) if (xch.res_class) *c = strdup(xch.res_class); XFree(xch.res_name); XFree(xch.res_class); } if (_ecore_xlib_sync) ecore_x_sync(); }
static void InternalLinkScreenAndGo( const char * WindowName ) { XGetWindowAttributes( CNFGDisplay, CNFGWindow, &CNFGWinAtt ); XGetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint ); if (!CNFGClassHint) { CNFGClassHint = XAllocClassHint(); if (CNFGClassHint) { CNFGClassHint->res_name = "cnping"; CNFGClassHint->res_class = "cnping"; XSetClassHint( CNFGDisplay, CNFGWindow, CNFGClassHint ); } else { fprintf( stderr, "Failed to allocate XClassHint!\n" ); } } else { fprintf( stderr, "Pre-existing XClassHint\n" ); } XSelectInput (CNFGDisplay, CNFGWindow, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask ); XSetStandardProperties( CNFGDisplay, CNFGWindow, WindowName, WindowName, None, NULL, 0, NULL ); CNFGWindowGC = XCreateGC(CNFGDisplay, CNFGWindow, 0, 0); CNFGPixmap = XCreatePixmap( CNFGDisplay, CNFGWindow, CNFGWinAtt.width, CNFGWinAtt.height, CNFGWinAtt.depth ); CNFGGC = XCreateGC(CNFGDisplay, CNFGPixmap, 0, 0); }
/* Returns a pointer to the profile of the currently selected * window, or defaultProfile if there is no specific profile for it or the window is invalid. */ char* getWindowClass(Window w) { char * result = NULL; if (w != None) { XClassHint* classHint = XAllocClassHint(); /* Read WM_CLASS member */ if (XGetClassHint(display, w, classHint)) { if(classHint->res_class != NULL) { result = malloc((strlen(classHint->res_name) + 1) * sizeof(char)); if(result != NULL) { strcpy(result, classHint->res_name); } XFree(classHint->res_class); } if(classHint->res_name != NULL) XFree(classHint->res_name); XFree(classHint); } } return result; }
void aosd_get_name(Aosd* aosd, XClassHint* result) { if (aosd == NULL || result == NULL) return; XGetClassHint(aosd->display, aosd->win, result); }
void qapp::run_client(Window w) // start new client { xwindow *client; int apnumber,format; Atom type; unsigned long nitems=0; unsigned long extra=0; unsigned char *data=NULL; stopautofocus(); if((client = cwindows[w]) != NULL) { client->map(); } else // new client { XClassHint ch; if(XGetClassHint(QX11Info::display(), w, &ch)) { QString clname(ch.res_class); QString cclname(ch.res_name); cclname += ','; cclname += clname; XFree(ch.res_name); XFree(ch.res_class); XGetWindowProperty(QX11Info::display(), w, kde_net_wm_system_tray_window_for, 0, 1L, FALSE, XA_WINDOW, &type, &format, &nitems, &extra, &data); if(data != NULL) XFree(data); if(! clname.isEmpty() && ((apnumber = apclients[clname]) || nitems)) { if(tb_ap->add(w, apnumber, clname)) // add to toolbar return; } if(! cclname.isEmpty() && ((apnumber = apclients[cclname]) || nitems)) { if(tb_ap->add(w, apnumber, cclname)) return; } } clients.prepend((client = new xwindow(w))); if(client->is_tileable() && tdesks[adesk] && ! client->is_unmapped()) { tile_order(tmaxclient); client->show(); XMapWindow(QX11Info::display(), client->client_id()); client->set_clientstate(NormalState); XSync(QX11Info::display(), FALSE); client->raise(); } } }
QString GestureHandler::getAppClass(Window window) const { XClassHint *classHint = XAllocClassHint(); XGetClassHint(QX11Info::display(), window, classHint); QString ret = classHint->res_class; XFree(classHint->res_class); XFree(classHint->res_name); return ret; }
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); } }
Window find_window(Window top,char *name) { char *wname,*iname; XClassHint xch; Window *children,foo; int revert_to_return; unsigned int nc; if (!strcmp(active_window_name,name)){ XGetInputFocus(dpy, &foo, &revert_to_return); return(foo); } /* First the base case */ if (XFetchName(dpy,top,&wname)){ if (!strncmp(wname,name,strlen(name))) { XFree(wname); debugprintf("found it by wname %x \n",top); return(top); /* found it! */ }; XFree(wname); }; if(XGetIconName(dpy,top,&iname)){ if (!strncmp(iname,name,strlen(name))) { XFree(iname); debugprintf("found it by iname %x \n",top); return(top); /* found it! */ }; XFree(iname); }; if(XGetClassHint(dpy,top,&xch)) { if(!strcmp(xch.res_class,name)) { XFree(xch.res_name); XFree(xch.res_class); debugprintf("res_class '%s' res_name '%s' %x \n", xch.res_class,xch.res_name,top); return(top); /* found it! */ }; if(!strcmp(xch.res_name,name)) { XFree(xch.res_name); XFree(xch.res_class); debugprintf("res_class '%s' res_name '%s' %x \n", xch.res_class,xch.res_name,top); return(top); /* found it! */ }; XFree(xch.res_name); XFree(xch.res_class); }; if(!XQueryTree(dpy,top,&foo,&foo,&children,&nc) || children==NULL) { return(0); /* no more windows here */ }; /* check all the sub windows */ for(;nc>0;nc--) { top = find_window(children[nc-1],name); if(top) break; /* we found it somewhere */ }; if(children!=NULL) XFree(children); return(top); }
GString* window_instance_to_g_string(Display* dpy, Window window) { XClassHint hint; if (0 == XGetClassHint(dpy, window, &hint)) { return g_string_new(""); } GString* string = g_string_new(hint.res_name ? hint.res_name : ""); if (hint.res_name) XFree(hint.res_name); if (hint.res_class) XFree(hint.res_class); return string; }
// ===== WindowClass() ===== QString LX11::WindowClass(WId win){ XClassHint hint; QString clss; if(0 != XGetClassHint(QX11Info::display(), win, &hint) ){ clss = QString(hint.res_class); //class is often capitalized properly, while name is not XFree(hint.res_name); XFree(hint.res_class); } return clss; }
QString Task::classClass() { XClassHint hint; if(XGetClassHint(qt_xdisplay(), _win, &hint)) { QString ch( hint.res_class ); XFree( hint.res_name ); XFree( hint.res_class ); return ch; } return QString::null; }
/** @brief Generates a name for the program frame the XClassHint. The returned pointer must be freed with XFree. @return A pointer to the null terminated string. **/ char * load_program_name(Display* display, Window window) { XClassHint program_hint; if(XGetClassHint(display, window, &program_hint)) { // printf("res_name %s, res_class %s\n", program_hint.res_name, program_hint.res_class); if(program_hint.res_name != NULL) XFree(program_hint.res_name); if(program_hint.res_class != NULL) return program_hint.res_class; } return NULL; }
void event_log(const char *e, Window w) { XClassHint chint; fprintf(stderr, "\n%s: %x", e, (unsigned int)w); if (w != None && XGetClassHint(display, w, &chint)) { fprintf(stderr, " %s", chint.res_class); XFree(chint.res_class); XFree(chint.res_name); } fprintf(stderr, "\n"); fflush(stderr); }
static void get_wmclass(task *tk) { ENTER; if (tk->ch.res_name) XFree(tk->ch.res_name); if (tk->ch.res_class) XFree(tk->ch.res_class); if (!XGetClassHint (gdk_display, tk->win, &tk->ch)) tk->ch.res_class = tk->ch.res_name = NULL; RET(); }
void qapp::run_client(Window w) // start new client { xwindow *client; int format; Atom type; unsigned long nitems=0; unsigned long extra=0; unsigned char *data=NULL; stopautofocus(); qDebug() << "qapp::run_client"; if((client = cwindows[w]) != NULL) { client->map(); } else // new client { XClassHint ch; if(XGetClassHint(QX11Info::display(), w, &ch)) { QString clname(ch.res_class); QString cclname(ch.res_name); cclname += ','; cclname += clname; XFree(ch.res_name); XFree(ch.res_class); XGetWindowProperty(QX11Info::display(), w, kde_net_wm_system_tray_window_for, 0, 1L, FALSE, XA_WINDOW, &type, &format, &nitems, &extra, &data); if(data != NULL) XFree(data); } client = new xwindow(w); clients.prepend(client); if(client->is_tileable() && tdesks[adesk] && ! client->is_unmapped()) { tile_order(tmaxclient); client->show(); XMapWindow(QX11Info::display(), client->client_id()); client->set_clientstate(NormalState); XSync(QX11Info::display(), FALSE); client->raise(); qDebug() << "New client created and raised **"; } } }
/* class_hints_return is really XTextProperty*, but to avoid extra includes, we'll use void* */ Status count_xgetclasshint (const char *fname, int line, Display * display, Window w, void *class_hint_return) { Status val; XClassHint *prop = class_hint_return; val = XGetClassHint (display, w, prop); if (val && prop->res_name) count_alloc (fname, line, (void *)prop->res_name, strlen (prop->res_name), C_XMEM | C_XGETCLASSHINT); if (val && prop->res_class) count_alloc (fname, line, (void *)prop->res_class, strlen (prop->res_class), C_XMEM | C_XGETCLASSHINT); return val; }
void get_window_class_name(Display *display, const Window window, char **win_class, char **win_name) { XClassHint class_hint; Status result = XGetClassHint(display, window, &class_hint); if (result != 0) { if (class_hint.res_class && win_class) *win_class = class_hint.res_class; if (class_hint.res_name&& win_name) *win_name = class_hint.res_name; } else fprintf(stderr, "couldn't get property WM_CLASS %d\n", result); }
void init_client(WM* wm, Window w, Client* c) { char* name; XClassHint* ch = XAllocClassHint(); memset(c,0,sizeof(Client)); c->win = w; c->manager = wm; c->x =c->y = 0; c->w = c->h = 10; if (XGetClassHint(wm->dpy, w, ch)) { sprintf(c->class,"%s",ch->res_class); if (ch->res_class) XFree(ch->res_class); if (ch->res_name) XFree(ch->res_name); }
void Toplevel::getResourceClass() { XClassHint classHint; if (XGetClassHint(display(), window(), &classHint)) { // Qt3.2 and older had this all lowercase, Qt3.3 capitalized resource class. // Force lowercase, so that workarounds listing resource classes still work. resource_name = QByteArray(classHint.res_name).toLower(); resource_class = QByteArray(classHint.res_class).toLower(); XFree(classHint.res_name); XFree(classHint.res_class); } else { resource_name = resource_class = QByteArray(); } }
void Client::getAppName(void) { XClassHint c; c.res_name = NULL; c.res_class = NULL; XGetClassHint(display(), clientId, &c); if (c.res_class != NULL) appName = QString::fromUtf8((char *)c.res_class); else if (c.res_name != NULL) appName = QString::fromUtf8((char *)c.res_class); else appName = clientName; XFree(c.res_name); XFree(c.res_class); }
QString WindowsHandler::get_window_class( WId id_P ) { if (!m_isX11) { return QString(); } XClassHint hints_ret; if( XGetClassHint( QX11Info::display(), id_P, &hints_ret ) == 0 ) // 0 means error return ""; QString ret( hints_ret.res_name ); ret += ' '; ret += hints_ret.res_class; XFree( hints_ret.res_name ); XFree( hints_ret.res_class ); return ret; }
void x11wmClass(Display *dsp, WId wid, QString resName) { //Display *dsp = x11Display(); // get the display //WId win = winId(); // get the window XClassHint classhint; // class hints // Get old class hint. It is important to save old class name XGetClassHint(dsp, wid, &classhint); XFree(classhint.res_name); const QByteArray latinResName = resName.toLatin1(); classhint.res_name = (char *)latinResName.data(); // res_name XSetClassHint(dsp, wid, &classhint); // set the class hints XFree(classhint.res_class); }
void qapp::run_client(Window w) // start new client { xwindow *client; int apnumber; if((client = cwindows.find(w)) != NULL) { client->map(); } else // new client { XClassHint ch; if(XGetClassHint(qt_xdisplay(), w, &ch)) { QString clname(ch.res_class); QString cclname(ch.res_name); cclname += ','; cclname += clname; XFree(ch.res_name); XFree(ch.res_class); if(! clname.isEmpty() && (apnumber = apclients[clname])) { if(tb_ap->add(w, apnumber, clname)) // add to toolbar return; } if(! cclname.isEmpty() && (apnumber = apclients[cclname])) { if(tb_ap->add(w, apnumber, cclname)) return; } } clients.prepend((client = new xwindow(w))); if(client->is_tileable() && tdesks[adesk] && ! client->is_unmapped()) { tile_order(tmaxclient); client->show(); XMapWindow(qt_xdisplay(), client->client_id()); client->set_clientstate(NormalState); XSync(qt_xdisplay(), FALSE); client->raise(); } } }
static int _xdo_window_match_classname(const xdo_t *xdo, Window window, regex_t *re) { XWindowAttributes attr; XClassHint classhint; XGetWindowAttributes(xdo->xdpy, window, &attr); if (XGetClassHint(xdo->xdpy, window, &classhint)) { if ((classhint.res_name) && (regexec(re, classhint.res_name, 0, NULL, 0) == 0)) { XFree(classhint.res_name); XFree(classhint.res_class); return True; } XFree(classhint.res_name); XFree(classhint.res_class); } return False; }
gboolean launcher_should_exit() { gboolean is_launcher_sub_window = FALSE; Display* _dsp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); XClassHint ch = {NULL, NULL}; if (XGetClassHint(_dsp, active_client_id, &ch)) { if (g_strcmp0(ch.res_name, "launcher") == 0) { is_launcher_sub_window = TRUE; } XFree(ch.res_name); XFree(ch.res_class); } return launcher_id != 0 && active_client_id != get_dock_window() && active_client_id != launcher_id && !is_launcher_sub_window; }
void Frame::get_wm_name() // get WM_NAME { char *name; Atom type; int format; unsigned long nitems=0; unsigned long extra=0; unsigned char *data=NULL; Atom _net_wm_name = XInternAtom(QX11Info::display(), "_NET_WM_NAME", False); Atom wm_locale_name = XInternAtom(QX11Info::display(), "WM_LOCALE_NAME", False); XGetWindowProperty(QX11Info::display(), c_win, _net_wm_name, 0, 500, FALSE, AnyPropertyType, &type, &format, &nitems, &extra, &data); if (data != NULL) { wm_name = QString::fromUtf8((char *)data); XFree(data); } else if (XFetchName(QX11Info::display(), c_win, &name) && name != NULL) { wm_name = name; XFree(name); } else // use class hints { XClassHint ch; if (XGetClassHint(QX11Info::display(), c_win, &ch)) { res_name = ch.res_name; res_class = ch.res_class; XFree(ch.res_name); XFree(ch.res_class); wm_name = res_name; } } qDebug() << "wm_name:" << wm_name; XGetWindowProperty(QX11Info::display(), c_win, wm_locale_name, 0, 500, FALSE, AnyPropertyType, &type, &format, &nitems, &extra, &data); if (data != NULL) { qDebug() << "wm_locale_name:" << QString::fromUtf8((char *)data); XFree(data); } }
XClassHint* xobj_get_wm_class(struct _xobj *p) { Window window = p->find_win_byatom(p, "WM_CLASS"); if (window == None) window = p->xWindow; XClassHint *wm_class = XAllocClassHint(); if (!XGetClassHint(p->xDisplay, window, wm_class)) { log_message(ERROR, "Can't get WM_CLASS"); XFree(wm_class->res_class); XFree(wm_class->res_name); XFree(wm_class); return NULL; } return wm_class; }
char* get_wm_class_name(Window window) { if (window == None) return NULL; Window named_window = find_window_with_atom(window, XInternAtom(main_window->display, "WM_CLASS", True)); if (named_window == None) { named_window = find_window_with_atom(window, XInternAtom(main_window->display, "WM_NAME", True)); if (named_window == None) return NULL; Atom type; int size; long nitems; Atom request = XInternAtom(main_window->display, "WM_NAME", False); unsigned char *data = get_win_prop(named_window, request, &nitems, &type, &size); if (nitems > 0) return (char *)data; return NULL; } XClassHint *wm_class = XAllocClassHint(); if (!XGetClassHint(main_window->display, named_window, wm_class)) { XFree(wm_class); return NULL; } char *string = strdup(wm_class->res_class); XFree(wm_class->res_class); XFree(wm_class->res_name); XFree(wm_class); return string; }
bool RotationDaemon::checkApplicationBlacklistToForceLandscape() { // Find active window Window activeWindow = activeWindowId(); // Now find what it is called XClassHint *xh = XAllocClassHint(); //Status s = XGetClassHint(QX11Info::display(), activeWindow, xh); qDebug() << "Active window is " << xh->res_name << xh->res_class; // clean up XFree(xh->res_name); XFree(xh->res_class); XFree(xh); return false; }
void _wnck_get_wmclass (Window xwindow, char **res_class, char **res_name) { XClassHint ch; char UNUSED_VARIABLE *retval; _wnck_error_trap_push (); ch.res_name = NULL; ch.res_class = NULL; XGetClassHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xwindow, &ch); _wnck_error_trap_pop (); retval = NULL; if (res_class) *res_class = NULL; if (res_name) *res_name = NULL; if (ch.res_name) { if (res_name) *res_name = latin1_to_utf8 (ch.res_name); XFree (ch.res_name); } if (ch.res_class) { if (res_class) *res_class = latin1_to_utf8 (ch.res_class); XFree (ch.res_class); } }