コード例 #1
0
ファイル: utils.cpp プロジェクト: BackupTheBerlios/wxbeos-svn
bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
{
    if (!wxResourceDatabase)
    {
        Display *display = wxGlobalDisplay();
        wxXMergeDatabases (wxTheApp, display);
    }

    XrmDatabase database;

    if (file != "")
    {
        char buffer[500];

        // Is this right? Trying to get it to look in the user's
        // home directory instead of current directory -- JACS
        (void) GetIniFile (buffer, file);

        wxNode *node = wxResourceCache.Find (buffer);
        if (node)
            database = (XrmDatabase) node->Data ();
        else
        {
            database = XrmGetFileDatabase (buffer);
            wxResourceCache.Append (buffer, (wxObject *) database);
        }
    }
    else
        database = wxResourceDatabase;

    XrmValue xvalue;
    char *str_type[20];
    char buf[150];
    strcpy (buf, section);
    strcat (buf, ".");
    strcat (buf, entry);

    Bool success = XrmGetResource (database, buf, "*", str_type,
        &xvalue);
    // Try different combinations of upper/lower case, just in case...
    if (!success)
    {
        buf[0] = (isupper (buf[0]) ? tolower (buf[0]) : toupper (buf[0]));
        success = XrmGetResource (database, buf, "*", str_type,
            &xvalue);
    }
    if (success)
    {
        if (*value)
            delete[] *value;

        *value = new char[xvalue.size + 1];
        strncpy (*value, xvalue.addr, (int) xvalue.size);
        return true;
    }
    return false;
}
コード例 #2
0
ファイル: x11_init.c プロジェクト: hgl888/glfw
// Retrieve system content scale via folklore heuristics
//
static void getSystemContentScale(float* xscale, float* yscale)
{
    // NOTE: Fall back to the display-wide DPI instead of RandR monitor DPI if
    //       Xft.dpi retrieval below fails as we don't currently have an exact
    //       policy for which monitor a window is considered to "be on"
    float xdpi = DisplayWidth(_glfw.x11.display, _glfw.x11.screen) *
        25.4f / DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen);
    float ydpi = DisplayHeight(_glfw.x11.display, _glfw.x11.screen) *
        25.4f / DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen);

    // NOTE: Basing the scale on Xft.dpi where available should provide the most
    //       consistent user experience (matches Qt, Gtk, etc), although not
    //       always the most accurate one
    char* rms = XResourceManagerString(_glfw.x11.display);
    if (rms)
    {
        XrmDatabase db = XrmGetStringDatabase(rms);
        if (db)
        {
            XrmValue value;
            char* type = NULL;

            if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value))
            {
                if (type && strcmp(type, "String") == 0)
                    xdpi = ydpi = atof(value.addr);
            }

            XrmDestroyDatabase(db);
        }
    }

    *xscale = xdpi / 96.f;
    *yscale = ydpi / 96.f;
}
コード例 #3
0
char *
GetResourceValueForSetValues(WNode *node, unsigned short *size)
{
    Arg args[1];
    char *ptr, *temp;
    XrmDatabase db = NULL;
    XrmValue value;

    XtSetArg(args[0], XtNstring, &ptr);
    XtGetValues(node->resources->res_box->value_wid, args, ONE);

    /*
     * This makes sure that exactly the same thing happens during a set
     * values, that would happend of we were to insert this value into
     * the resource database.
     */

    temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2));
    sprintf(temp, "%s:%s", RESOURCE_NAME, ptr);
    XrmPutLineResource(&db, temp);
    XtFree(temp);

    XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);

    ptr = XtMalloc(sizeof(char) * value.size);
    memmove( ptr, value.addr, value.size);
    XrmDestroyDatabase(db);
    
    *size = (unsigned short) value.size;
    return(ptr);
}
コード例 #4
0
ファイル: resources.c プロジェクト: Bluerise/bitrig-xenocara
char *
get_string_resource (char *res_name, char *res_class)
{
  XrmValue value;
  char	*type;
  char full_name [1024], full_class [1024];
  int result;

  result = snprintf(full_name, sizeof(full_name), "%s.%s", 
      progname, res_name);
  if (result == -1 || result >= sizeof(full_name)) {
	  fprintf(stderr, "%s: resource name too long: %s.%s\n", progname,
	      progname, res_name);
	  return 0;
  }
  result = snprintf(full_class, sizeof(full_class), "%s.%s", 
      progclass, res_class);
  if (result == -1 || result >= sizeof(full_class)) {
	 fprintf(stderr, "%s: resource name too long: %s.%s\n", progname,
	      progclass, res_class);
	  return 0;
  }
  if (XrmGetResource (db, full_name, full_class, &type, &value))
    {
      char *str = (char *) malloc (value.size + 1);
      strncpy (str, (char *) value.addr, value.size);
      str [value.size] = 0;
      return str;
    }
  return 0;
}
コード例 #5
0
ファイル: cursor_glyph.c プロジェクト: chhetrisushil/alock
static void module_loadxrdb(XrmDatabase xrdb) {

    XrmValue value;
    char *type;

    if (XrmGetResource(xrdb, "alock.cursor.glyph.name",
                "ALock.Cursor.Glyph.Name", &type, &value))
        module_set_cursor_by_name(value.addr);

    if (XrmGetResource(xrdb, "alock.cursor.glyph.foreground",
                "ALock.Cursor.Glyph.Foreground", &type, &value))
        data.colorname_fg = strdup(value.addr);

    if (XrmGetResource(xrdb, "alock.cursor.glyph.background",
                "ALock.Cursor.Glyph.Background", &type, &value))
        data.colorname_bg = strdup(value.addr);

}
コード例 #6
0
ファイル: ax.c プロジェクト: radekp/spectemu
char *aX_get_resource(const char *resname, const char* resclass)
{
    XrmValue value;
    char *str_type;

    if(XrmGetResource(rDB, resname, resclass,
                      &str_type, &value)) 
        return (char *)value.addr;
    else return NULL;
}
コード例 #7
0
ファイル: bg_blank.c プロジェクト: Arkq/alock
static void module_loadxrdb(XrmDatabase xrdb) {

    XrmValue value;
    char *type;

    if (XrmGetResource(xrdb, "alock.background.blank.color",
                "ALock.Background.Blank.Color", &type, &value))
        data.colorname = strdup(value.addr);

}
コード例 #8
0
ファイル: resource.c プロジェクト: 007durgesh219/jessies
extern void
get_resources(void) {
    XrmDatabase db;
    XrmValue value;
    char * resource_manager;
    char * type;
    int i;

    /* Set our fall-back defaults. */
    font_name = DEFAULT_FONT;
    for (i = 0; i < 6; i++)
        command[i] = 0;
    view_command = 0;
    
    resource_manager = XResourceManagerString(dpy);
    if (resource_manager == 0)
        return;

    XrmInitialize();
    db = XrmGetStringDatabase(resource_manager);
    if (db == 0)
        return;

    /* Font. */
    if (XrmGetResource(db, "menu.font", "Font", &type, &value) == True)
        if (strcmp(type, "String") == 0)
            font_name = strdup((char *) value.addr);

    /* Button commands. */
    for (i = 1; i < 6; i++) {
        char resource[15];
        sprintf(resource, "clock.button%i", i);
        if (XrmGetResource(db, resource, "String", &type, &value) == True)
            if (strcmp(type, "String") == 0)
                command[i] = strdup((char *) value.addr);
    }
    
    /* View command. */
    if (XrmGetResource(db, "clock.viewCommand", "String", &type, &value) == True)
        if (strcmp(type, "String") == 0)
            view_command = strdup((char *) value.addr);
}
コード例 #9
0
ファイル: xcommon.c プロジェクト: UlricE/SiagOffice
void theme_init(Display *display)
{
        char b[1024], *tr;
	char *p, *q;
        XrmDatabase themedb, olddb;
        XrmValue vr;
 
        sprintf(b, "%s/theme", siag_basedir);
        themedb = XrmGetFileDatabase(b);
	if (!themedb) {	/* use kde2 as default */
		sprintf(b, "%s/common/themes/theme.kde2", datadir);
		themedb = XrmGetFileDatabase(b);
	}
        if (themedb) {
                olddb = XrmGetDatabase(display);
                XrmMergeDatabases(themedb, &olddb);
                XrmSetDatabase(display, olddb);

                if (XrmGetResource(olddb, "PIXPATH", XtNstring, &tr, &vr)) {
			strcpy(b, "PIXPATH=");
			p = b+strlen(b);
			q = vr.addr;
			while (*q) {
				if (q[0] == '.' && q[1] == '.' && q[2] == '.') {
					strcpy(p, datadir);
					p += strlen(p);
					q += 2;
				} else {
					*p++ = *q;
				}
				q++;
			}
			*p = '\0';
                        putenv(MwStrdup(b));
                }
                if (XrmGetResource(olddb, "XAWM_THEME", XtNstring, &tr, &vr)) {
                        sprintf(b, "XAWM_THEME=%s", vr.addr);
                        putenv(MwStrdup(b));
                }
        }
}
コード例 #10
0
ファイル: csfindNX.c プロジェクト: dikerex/theqvd
static int
FindXDPSNXInXrmDatabase(
     Display *dpy,
     char **host,
     int *transport,
     int *port)
{
  XrmDatabase rDB = NULL;	/* for merged database */
  XrmDatabase serverDB;
  char filenamebuf[1024];
  char *filename = &filenamebuf[0];
  char *env, *str_type;
  char name[255];
  XrmValue value;
  int retVal = !Success;

  XrmInitialize();
  (void) strcpy(name, "/usr/lib/X11/app-defaults/");
  (void) strcat(name, XDPSNX_X_CLASS_NAME);
  
  /* try to get application defaults file, if there is any */
  XrmMergeDatabases(XrmGetFileDatabase(name), &rDB);

  /* try to merge the server defaults.  if not defined then use .Xdefaults */
  if (XResourceManagerString(dpy) != NULL) {
    serverDB = XrmGetStringDatabase(XResourceManagerString(dpy));
  } else {			/* use the .Xdefaults */
    (void) getHomeDir(filename);
    (void) strcat(filename, "/.Xdefaults");
    
    serverDB = XrmGetFileDatabase(filename);
  }
  XrmMergeDatabases(serverDB, &rDB);
 
  /* try the XENVIRONMENT file, or if not defined, then .Xdefaults */
  if ((env = getenv("XENVIRONMENT")) == NULL) {
    int len;
    env = getHomeDir(filename);
    (void) strcat(filename, "/.Xdefaults-");
    len = strlen(env);
    (void) gethostname(env+len, 1024-len);
  }
  XrmMergeDatabases(XrmGetFileDatabase(env), &rDB);

  /* Now that the database is built, try to extract the values we want. */

  if (XrmGetResource(rDB, XDPSNX_X_RESOURCE, XDPSNX_X_CLASS_NAME, &str_type,
		     &value) == True) {
    retVal = ParseAgentString((char *) value.addr, host, transport, port);
  }
  (void) XrmDestroyDatabase(rDB);
  return(retVal);
}
コード例 #11
0
ファイル: xclip.c プロジェクト: codingsnippets/xclip
/* process noutf8 and target command line options */
static void
doOptTarget(void)
{
    /* check for -noutf8 */
    if (XrmGetResource(opt_db, "xclip.noutf8", "Xclip.noutf8", &rec_typ, &rec_val)
	) {
	if (fverb == OVERBOSE)	/* print in verbose mode only */
	    fprintf(stderr, "Using old UNICODE instead of UTF8.\n");
    }
    else if (XrmGetResource(opt_db, "xclip.target", "Xclip.Target", &rec_typ, &rec_val)
	) {
	target = XInternAtom(dpy, rec_val.addr, False);
	if (fverb == OVERBOSE)	/* print in verbose mode only */
	    fprintf(stderr, "Using %s.\n", rec_val.addr);
    }
    else {
	target = XA_UTF8_STRING(dpy);
	if (fverb == OVERBOSE)	/* print in verbose mode only */
	    fprintf(stderr, "Using UTF8_STRING.\n");
    }
}
コード例 #12
0
ファイル: initx.c プロジェクト: fricas/fricas
static void
open_window(Window w)
{
    int x = 0, y = 0;
    /*int border_width = 2;*/
    unsigned int width = 1;
    unsigned int height = 1;
    unsigned int fwidth = 0, fheight = 0;
    unsigned int xadder = 0, yadder = 0;
    char *str_type[50];
    XrmValue value;

    char userdefaults[50], progdefaults[50];

    strcpy(progdefaults, "=700x450+0+0");
    if (XrmGetResource(rDB, "FriCAS.hyperdoc.Geometry",
        "FriCAS.hyperdoc.Geometry", str_type, &value) == True)
    {
        strncpy(userdefaults, value.addr, (int) value.size);
    }
    else
        strcpy(userdefaults, progdefaults);

    XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
              0, fwidth, fheight, xadder, yadder,
              &x, &y, ( int *)&width,( int *) &height);

    gWindow->border_width = get_border_properties();

    gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber),
                                    x, y, width, height, gWindow->border_width,
                                    gBorderColor,
                                    WhitePixel(gXDisplay, gXScreenNumber));

    gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow,
                                         1, 1, 1, 1, 0,
                                         gBorderColor,
                                         WhitePixel(gXDisplay, gXScreenNumber));


    makeScrollBarWindows();
    makeTitleBarWindows();

    /* Now set all the little properties for the top level window */

    set_name_and_icon();
    set_size_hints(w);
    XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask);
    XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask);
    XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor);
}
コード例 #13
0
ファイル: xtut7.c プロジェクト: artem-yazkov/touch
unsigned long getColour(Display *dpy,  XrmDatabase db, char *name,
			char *cl, char *def){
	XrmValue v;
	XColor col1, col2;
	Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy));
	char * type;

	if (XrmGetResource(db, name, cl, &type, &v)
			&& XAllocNamedColor(dpy, cmap, v.addr, &col1, &col2)) {
	} else {
		XAllocNamedColor(dpy, cmap, def, &col1, &col2);
	}
	return col2.pixel;
}
コード例 #14
0
ファイル: SmDB.c プロジェクト: juddy/edcde
static Boolean
_getIntResource(XrmDatabase xrmDB, char *fmtStr,
		char *clientID, int *resourcePtr, int defaultVal)
{
    char *resourceType;
    XrmValue resourceValue;

    if (NULL == resourceBuf) resourceBuf = XtMalloc(RESOURCE_BUF_SZ);
    sprintf(resourceBuf, fmtStr, clientID);
    *resourcePtr = (XrmGetResource(xrmDB, resourceBuf, resourceBuf,
				   &resourceType, &resourceValue)) ?
			atoi(resourceValue.addr) : defaultVal;

    return True;
}
コード例 #15
0
ファイル: main.c プロジェクト: SparklePigBang/dzen
/* Read display styles from X resources. */
static void
x_read_resources(void) {
	XrmDatabase xdb;
	char* xrm;
	char* datatype[20];
	XrmValue xvalue;

	XrmInitialize();
	xrm = XResourceManagerString(dzen.dpy);
	if( xrm != NULL ) {
		xdb = XrmGetStringDatabase(xrm);
		if( XrmGetResource(xdb, "dzen2.font", "*", datatype, &xvalue) == True )
			dzen.fnt = estrdup(xvalue.addr);
		if( XrmGetResource(xdb, "dzen2.foreground", "*", datatype, &xvalue) == True )
			dzen.fg  = estrdup(xvalue.addr);
		if( XrmGetResource(xdb, "dzen2.background", "*", datatype, &xvalue) == True )
			dzen.bg  = estrdup(xvalue.addr);
		if( XrmGetResource(xdb, "dzen2.titlename", "*", datatype, &xvalue) == True )
			dzen.title_win.name  = estrdup(xvalue.addr);
		if( XrmGetResource(xdb, "dzen2.slavename", "*", datatype, &xvalue) == True )
			dzen.slave_win.name  = estrdup(xvalue.addr);
		XrmDestroyDatabase(xdb);
	}
}
コード例 #16
0
ファイル: prefFile.c プロジェクト: adrian-bl/nedit
static void readPrefs(XrmDatabase prefDB, XrmDatabase appDB,
        const char *appName, const char *appClass, PrefDescripRec *rsrcDescrip,
        int nRsrc, int overlay)
{
    char rsrcName[256], rsrcClass[256], *valueString, *type;
    XrmValue rsrcValue;
    int i;

    /* read each resource, trying first the preferences file database, then
       the application database, then the default value if neither are found */
    for (i=0; i<nRsrc; i++) {
    	sprintf(rsrcName,"%s.%s", appName, rsrcDescrip[i].name);
    	sprintf(rsrcClass, "%s.%s", appClass, rsrcDescrip[i].class);
    	if (prefDB!=NULL &&
    	       XrmGetResource(prefDB, rsrcName, rsrcClass, &type, &rsrcValue)) {
    	    if (strcmp(type, XmRString)) {
                fprintf(stderr,"nedit: Internal Error: Unexpected resource type, %s\n",
    	    		type);
    	    	return;
    	    }
    	    valueString = rsrcValue.addr;
    	} else if (XrmGetResource(appDB,rsrcName,rsrcClass,&type,&rsrcValue)) {
    	    if (strcmp(type, XmRString)) {
                fprintf(stderr,"nedit: Internal Error: Unexpected resource type, %s\n",
    	    		type);
    	    	return;
    	    }
    	    valueString = rsrcValue.addr;
    	} else
    	    valueString = rsrcDescrip[i].defaultString;
	if (overlay && valueString == rsrcDescrip[i].defaultString)
	    continue;
    	if (!stringToPref(valueString, &rsrcDescrip[i]))
            fprintf(stderr, "nedit: Could not read value of resource %s\n", rsrcName);
    }
}
コード例 #17
0
ファイル: tests_match.c プロジェクト: Airblader/xcb-util-xrm
static char *check_get_resource_xlib(const char *str_database, const char *res_name, const char *res_class) {
    int res_code;
    char *res_type;
    XrmValue res_value;
    char *result;

    XrmDatabase database = XrmGetStringDatabase(str_database);
    res_code = XrmGetResource(database, res_name, res_class, &res_type, &res_value);

    if (res_code) {
        result = strdup((char *)res_value.addr);
    } else {
        result = NULL;
    }

    XrmDestroyDatabase(database);
    return result;
}
コード例 #18
0
ファイル: window.c プロジェクト: muennich/sxiv
const char* win_res(Display *dpy, const char *name, const char *def)
{
	char *type;
	XrmValue ret;
	XrmDatabase db;
	char *res_man;

	XrmInitialize();

	if ((res_man = XResourceManagerString(dpy)) != NULL &&
	    (db = XrmGetStringDatabase(res_man)) != NULL &&
	    XrmGetResource(db, name, name, &type, &ret) && STREQ(type, "String"))
	{
		return ret.addr;
	} else {
		return def;
	}
}
コード例 #19
0
static int Get_resource(XrmDatabase db, char *myName, char *myClass,
			char *resource, char *fallback, char *result,
			unsigned size)
{
    int			i,
			len;
    char		str_name[80],
			str_class[80],
			*str_type[10];
    XrmValue		rmValue;

    sprintf(str_name, "%s.%s", myName, resource);
    sprintf(str_class, "%s.%c%s", myClass,
	    isupper(*resource) ? toupper(*resource) : *resource, resource + 1);

    if (XrmGetResource(db, str_name, str_class, str_type, &rmValue) == True) {
	if (rmValue.addr == NULL) {
	    len = 0;
	} else {
	    len = MIN(rmValue.size, size - 1);
	    strncpy(result, rmValue.addr, len);
	}
	result[len] = '\0';
	for (i = 0; i < NELEM(opts); i++) {
	    if (opts[i].argKind == XrmoptionIsArg
		&& (strcmp(result, opts[i].option) == 0
		    || strcmp(result, opts[i].specifier) == 0)) {
		strncpy(result, "True", size);
		result[size - 1] = '\0';
		break;
	    }
	}
	return 1;
    }
    if (fallback != NULL) {
	strncpy(result, fallback, size - 1);
	result[size - 1] = '\0';
    } else {
	result[0] = '\0';
    }
    return 0;
}
コード例 #20
0
ファイル: xclip.c プロジェクト: svn2github/foo
/* process selection command line option */
static void doOptSel (void)
{
	/* set selection to work with */
	if (
		XrmGetResource(
			opt_db,
			"xclip.selection",
			"Xclip.Selection",
			&rec_typ,
			&rec_val
		)
	)
	{
		switch (tolower(rec_val.addr[0]))
		{
			case 'p':
				sseln = XA_PRIMARY;
				break;
			case 's':
				sseln = XA_SECONDARY;
				break;
			case 'c':
				sseln = XA_CLIPBOARD(dpy);
				break;
		}
    
		if (fverb == OVERBOSE)
		{
			fprintf(stderr, "Using selection: ");
	   
			if (sseln == XA_PRIMARY)
				fprintf(stderr, "XA_PRIMARY");
			if (sseln == XA_SECONDARY)
				fprintf(stderr, "XA_SECONDARY");
			if (sseln == XA_CLIPBOARD(dpy))
				fprintf(stderr, "XA_CLIPBOARD");

			fprintf(stderr, "\n");
		}
	}
}
コード例 #21
0
ファイル: resources.c プロジェクト: dylex/xdaliclock
char *
get_string_resource (char *res_name, char *res_class)
{
  XrmValue value;
  char	*type;
  char full_name [1024], full_class [1024];
  strcpy (full_name, progname);
  strcat (full_name, ".");
  strcat (full_name, res_name);
  strcpy (full_class, progclass);
  strcat (full_class, ".");
  strcat (full_class, res_class);
  if (XrmGetResource (db, full_name, full_class, &type, &value))
    {
      char *str = (char *) malloc (value.size + 1);
      strncpy (str, (char *) value.addr, value.size);
      str [value.size] = 0;
      return str;
    }
  return 0;
}
コード例 #22
0
ファイル: SmDB.c プロジェクト: juddy/edcde
static Boolean
_getStringResource(XrmDatabase xrmDB, char *fmtStr,
		   char *clientID, char **resourcePtr, char *defaultVal)
{
    char *resourceType;
    XrmValue resourceValue;

    if (NULL == resourceBuf) resourceBuf = XtMalloc(RESOURCE_BUF_SZ);
    sprintf(resourceBuf, fmtStr, clientID);
    if (XrmGetResource(xrmDB, resourceBuf, resourceBuf,
		       &resourceType, &resourceValue))
    {
	if ((*resourcePtr = XtNewString(resourceValue.addr)) == (char *)NULL)
	    return False;

	return True;
    }

    *resourcePtr = defaultVal;
    return True;
}
コード例 #23
0
ファイル: xtut7.c プロジェクト: artem-yazkov/touch
XFontSet getFont(Display *dpy, XrmDatabase db, char *name,
		char *cl, char *def){
	XrmValue v;
	char * type;
	XFontSet font = NULL;
	int nmissing;
	char **missing;
	char *def_string;

	if (XrmGetResource(db, name, cl, &type, &v)){
		if (v.addr)
			font = XCreateFontSet(dpy, v.addr, &missing, &nmissing, &def_string);
	}
	if (!font) {
		if (v.addr)
		fprintf(stderr, "unable to load preferred font: %s using fixed\n", v.addr);
		else 
		fprintf(stderr, "couldn't figure out preferred font\n");
		font = XCreateFontSet(dpy, def, &missing, &nmissing, &def_string);
	}
	XFreeStringList(missing);
	return font;
}
コード例 #24
0
ファイル: options.c プロジェクト: GrahamCobb/maemo-xsisusb
char *
GetOptionDescription(char *module, char *option)
{
    char *type;
    XrmValue value;
    char query[256];
    unsigned char *ptr;

    InitializeOptionsDatabase();

    XmuSnprintf(query, sizeof(query), "%s.%s", module, option);
    ptr = (unsigned char*)strchr(query, '.') + 1;
    for (; *ptr; ptr++) {
	if (*ptr == '_' || *ptr == ' ' || *ptr == '\t')
	    memmove(ptr, ptr + 1, strlen((char*)ptr) + 1);
    }
    for (ptr = (unsigned char*)query; *ptr; ptr++)
	*ptr = tolower(*ptr);
    if (XrmGetResource(options_xrm, query, "Module.Option", &type, &value))
	return ((char*)value.addr);

    return (NULL);
}
コード例 #25
0
void
HelpAgent::display_help (const String locatoridResourceString)
{
  Wait_Cursor bob;

  if (f_helper == NULL)
    create_ui();

  if (f_appXrmDb)
  {
    char* type;
    XrmValue value;

    if(env().debug())
      cerr << "Resource string: " << locatoridResourceString << endl;
    if(XrmGetResource(f_appXrmDb, locatoridResourceString,
                        locatoridResourceString, &type, &value ))
    {
      if(env().debug())
        cerr << "Value: " << value.addr << endl;
      XtVaSetValues(f_helper,
                    DtNhelpType, DtHELP_TYPE_TOPIC,
                    DtNhelpVolume, "Infomgr",
                    DtNlocationId, value.addr,
                    XmNdialogStyle, XmDIALOG_MODELESS,
                    NULL);
      XtManageChild(f_helper);
      Popup();
    }
    else
    {
      message_mgr().error_dialog (UAS_String(
                    CATGETS(Set_Messages, 3, "No help available")));
    }
  }
}
コード例 #26
0
ファイル: evas_engine.c プロジェクト: nashidau/Evas-Next
static Eina_Bool
xrdb_user_query(const char *name, const char *cls, char **type, XrmValue *val)
{
   time_t last = xrdb_user.last_stat, now = time(NULL);

   xrdb_user.last_stat = now;
   if (last != now) /* don't stat() more than once every second */
     {
	struct stat st;
	const char *home = getenv("HOME");
	char tmp[PATH_MAX];

	if (!home) goto failed;
	snprintf(tmp, sizeof(tmp), "%s/.Xdefaults", home);
	if (stat(tmp, &st) != 0) goto failed;
	if (xrdb_user.last_mtime != st.st_mtime)
	  {
	     if (xrdb_user.db) XrmDestroyDatabase(xrdb_user.db);
	     xrdb_user.db = XrmGetFileDatabase(tmp);
	     if (!xrdb_user.db) goto failed;
	     xrdb_user.last_mtime = st.st_mtime;
	  }
     }

   if (!xrdb_user.db) return EINA_FALSE;
   return XrmGetResource(xrdb_user.db, name, cls, type, val);

 failed:
   if (xrdb_user.db)
     {
	XrmDestroyDatabase(xrdb_user.db);
	xrdb_user.db = NULL;
     }
   xrdb_user.last_mtime = 0;
   return EINA_FALSE;
}
コード例 #27
0
ファイル: x11-init.c プロジェクト: 00001/plan9port
Memimage*
_xattach(char *label, char *winsize)
{
	char *argv[2], *disp;
	int i, havemin, height, mask, n, width, x, xrootid, y;
	Rectangle r;
	XClassHint classhint;
	XDrawable pmid;
	XPixmapFormatValues *pfmt;
	XScreen *xscreen;
	XSetWindowAttributes attr;
	XSizeHints normalhint;
	XTextProperty name;
	XVisualInfo xvi;
	XWindow xrootwin;
	XWindowAttributes wattr;
	XWMHints hint;
	Atom atoms[2];

	/*
	if(XInitThreads() == 0){
		fprint(2, "XInitThreads failed\n");
		abort();
	}
	*/

	/*
	 * Connect to X server.
	 */
	_x.display = XOpenDisplay(NULL);
	if(_x.display == nil){
		disp = getenv("DISPLAY");
		werrstr("XOpenDisplay %s: %r", disp ? disp : ":0");
		free(disp);
		return nil;
	}
	_x.fd = ConnectionNumber(_x.display);
	XSetErrorHandler(xerror);
	XSetIOErrorHandler(xioerror);
	xrootid = DefaultScreen(_x.display);
	xrootwin = DefaultRootWindow(_x.display);

	/* 
	 * Figure out underlying screen format.
	 */
	if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 24;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 16;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 15;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){
		if(_x.depth > 8){
			werrstr("can't deal with colormapped depth %d screens",
				_x.depth);
			goto err0;
		}
		_x.vis = xvi.visual;
		_x.depth = 8;
	}
	else{
		_x.depth = DefaultDepth(_x.display, xrootid);
		if(_x.depth != 8){
			werrstr("can't understand depth %d screen", _x.depth);
			goto err0;
		}
		_x.vis = DefaultVisual(_x.display, xrootid);
	}

	if(DefaultDepth(_x.display, xrootid) == _x.depth)
		_x.usetable = 1;

	/*
	 * _x.depth is only the number of significant pixel bits,
	 * not the total number of pixel bits.  We need to walk the
	 * display list to find how many actual bits are used
	 * per pixel.
	 */
	_x.chan = 0;
	pfmt = XListPixmapFormats(_x.display, &n);
	for(i=0; i<n; i++){
		if(pfmt[i].depth == _x.depth){
			switch(pfmt[i].bits_per_pixel){
			case 1:	/* untested */
				_x.chan = GREY1;
				break;
			case 2:	/* untested */
				_x.chan = GREY2;
				break;
			case 4:	/* untested */
				_x.chan = GREY4;
				break;
			case 8:
				_x.chan = CMAP8;
				break;
			case 15:
				_x.chan = RGB15;
				break;
			case 16: /* how to tell RGB15? */
				_x.chan = RGB16;
				break;
			case 24: /* untested (impossible?) */
				_x.chan = RGB24;
				break;
			case 32:
				_x.chan = XRGB32;
				break;
			}
		}
	}
	if(_x.chan == 0){
		werrstr("could not determine screen pixel format");
		goto err0;
	}

	/*
	 * Set up color map if necessary.
	 */
	xscreen = DefaultScreenOfDisplay(_x.display);
	_x.cmap = DefaultColormapOfScreen(xscreen);
	if(_x.vis->class != StaticColor){
		plan9cmap();
		setupcmap(xrootwin);
	}

	/*
	 * We get to choose the initial rectangle size.
	 * This is arbitrary.  In theory we should read the
	 * command line and allow the traditional X options.
	 */
	mask = 0;
	x = 0;
	y = 0;
	if(winsize && winsize[0]){
		if(parsewinsize(winsize, &r, &havemin) < 0)
			sysfatal("%r");
	}else{
		/*
		 * Parse the various X resources.  Thanks to Peter Canning.
		 */
		char *screen_resources, *display_resources, *geom, 
			*geomrestype, *home, *file;
		XrmDatabase database;
		XrmValue geomres;

		database = XrmGetDatabase(_x.display);
		screen_resources = XScreenResourceString(xscreen);
		if(screen_resources != nil){
			XrmCombineDatabase(XrmGetStringDatabase(screen_resources), &database, False);
			XFree(screen_resources);
		}

		display_resources = XResourceManagerString(_x.display);
		if(display_resources == nil){
			home = getenv("HOME");
			if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){
				XrmCombineFileDatabase(file, &database, False);
				free(file);
			}
			free(home);
		}else
			XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False);

		geom = smprint("%s.geometry", label);
		if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres))
			mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height);
		free(geom);

		if((mask & WidthValue) && (mask & HeightValue)){
			r = Rect(0, 0, width, height);
		}else{
			r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
					HeightOfScreen(xscreen)*3/4);
			if(Dx(r) > Dy(r)*3/2)
				r.max.x = r.min.x + Dy(r)*3/2;
			if(Dy(r) > Dx(r)*3/2)
				r.max.y = r.min.y + Dx(r)*3/2;
		}
		if(mask & XNegative){
			x += WidthOfScreen(xscreen);
		}
		if(mask & YNegative){
			y += HeightOfScreen(xscreen);
		}
		havemin = 0;
	}
	screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen));
	windowrect = r;

	memset(&attr, 0, sizeof attr);
	attr.colormap = _x.cmap;
	attr.background_pixel = ~0;
	attr.border_pixel = 0;
	_x.drawable = XCreateWindow(
		_x.display,	/* display */
		xrootwin,	/* parent */
		x,		/* x */
		y,		/* y */
		Dx(r),		/* width */
	 	Dy(r),		/* height */
		0,		/* border width */
		_x.depth,	/* depth */
		InputOutput,	/* class */
		_x.vis,		/* visual */
				/* valuemask */
		CWBackPixel|CWBorderPixel|CWColormap,
		&attr		/* attributes (the above aren't?!) */
	);

	/*
	 * Label and other properties required by ICCCCM.
	 */
	memset(&name, 0, sizeof name);
	if(label == nil)
		label = "pjw-face-here";
	name.value = (uchar*)label;
	name.encoding = XA_STRING;
	name.format = 8;
	name.nitems = strlen((char*)name.value);

	memset(&normalhint, 0, sizeof normalhint);
	normalhint.flags = PSize|PMaxSize;
	if(winsize && winsize[0]){
		normalhint.flags &= ~PSize;
		normalhint.flags |= USSize;
		normalhint.width = Dx(r);
		normalhint.height = Dy(r);
	}else{
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags &= ~PSize;
			normalhint.flags |= USSize;
			normalhint.width = width;
			normalhint.height = height;
		}
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags |= USPosition;
			normalhint.x = x;
			normalhint.y = y;
		}
	}

	normalhint.max_width = WidthOfScreen(xscreen);
	normalhint.max_height = HeightOfScreen(xscreen);

	memset(&hint, 0, sizeof hint);
	hint.flags = InputHint|StateHint;
	hint.input = 1;
	hint.initial_state = NormalState;

	memset(&classhint, 0, sizeof classhint);
	classhint.res_name = label;
	classhint.res_class = label;

	argv[0] = label;
	argv[1] = nil;

	XSetWMProperties(
		_x.display,	/* display */
		_x.drawable,	/* window */
		&name,		/* XA_WM_NAME property */
		&name,		/* XA_WM_ICON_NAME property */
		argv,		/* XA_WM_COMMAND */
		1,		/* argc */
		&normalhint,	/* XA_WM_NORMAL_HINTS */
		&hint,		/* XA_WM_HINTS */
		&classhint	/* XA_WM_CLASSHINTS */
	);
	XFlush(_x.display);

	if(havemin){
		XWindowChanges ch;

		memset(&ch, 0, sizeof ch);
		ch.x = r.min.x;
		ch.y = r.min.y;
		XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
		/*
		 * Must pretend origin is 0,0 for X.
		 */
		r = Rect(0,0,Dx(r),Dy(r));
	}
	/*
	 * Look up clipboard atom.
	 */
	_x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
	_x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
	_x.targets = XInternAtom(_x.display, "TARGETS", False);
	_x.text = XInternAtom(_x.display, "TEXT", False);
	_x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
	_x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
	_x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
	_x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);

	atoms[0] = _x.takefocus;
	atoms[1] = _x.losefocus;
	XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
		PropModeReplace, (uchar*)atoms, 2);

	/*
	 * Put the window on the screen, check to see what size we actually got.
	 */
	XMapWindow(_x.display, _x.drawable);
	XSync(_x.display, False);

	if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
		fprint(2, "XGetWindowAttributes failed\n");
	else if(wattr.width && wattr.height){
		if(wattr.width != Dx(r) || wattr.height != Dy(r)){
			r.max.x = wattr.width;
			r.max.y = wattr.height;
		}
	}else
		fprint(2, "XGetWindowAttributes: bad attrs\n");

	/*
	 * Allocate our local backing store.
	 */
	_x.screenr = r;
	_x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
	_x.nextscreenpm = _x.screenpm;
	_x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);

	/*
	 * Allocate some useful graphics contexts for the future.
	 */
	_x.gcfill	= xgc(_x.screenpm, FillSolid, -1);
	_x.gccopy	= xgc(_x.screenpm, -1, -1);
	_x.gcsimplesrc 	= xgc(_x.screenpm, FillStippled, -1);
	_x.gczero	= xgc(_x.screenpm, -1, -1);
	_x.gcreplsrc	= xgc(_x.screenpm, FillTiled, -1);

	pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
	_x.gcfill0	= xgc(pmid, FillSolid, 0);
	_x.gccopy0	= xgc(pmid, -1, -1);
	_x.gcsimplesrc0	= xgc(pmid, FillStippled, -1);
	_x.gczero0	= xgc(pmid, -1, -1);
	_x.gcreplsrc0	= xgc(pmid, FillTiled, -1);
	XFreePixmap(_x.display, pmid);

	return _x.screenimage;

err0:
	/*
	 * Should do a better job of cleaning up here.
	 */
	XCloseDisplay(_x.display);
	return nil;
}
コード例 #28
0
ファイル: X_driver.c プロジェクト: zhangjinde/zephyr
char *
get_string_resource(string name,
                    string class)
{
    string full_name, full_class;
    int status;
    char *type;
    XrmValue value;

    full_name = string_Concat(APPNAME, ".");
    full_name = string_Concat2(full_name, name);
    full_class = string_Concat(APPCLASS, ".");
    full_class = string_Concat2(full_class, class);

    status = XrmGetResource(x_resources, full_name, full_class, &type, &value);
    free(full_name);
    free(full_class);

    if (status != True)
        return(NULL);

    if (string_Neq(type, "String"))
        return(NULL);

    return(value.addr);
}

/*
 *
 */
コード例 #29
0
static void 
getDtwmValues( )
{
    char *str_type_return;
    XrmValue value_return;
    XrmValue    cvt_value;
    XrmDatabase db;
    Boolean status;
    char *string;

    db = XtDatabase(style.display);

    /* Get KeyboardFocusPolicy value */
    if (status = XrmGetResource (db, "dtwm.keyboardFocusPolicy",
                                 "Dtwm.KeyboardFocusPolicy",
                                 &str_type_return, &value_return))
    {
        /* make local copy of string */
        string = (char *) XtMalloc( value_return.size );
        strcpy (string, value_return.addr);

        /* convert to lower case */
        _DtWmParseToLower((unsigned char *)string);

        if (strcmp(string, "pointer") == 0)
        {
            XmToggleButtonGadgetSetState (dtwm.pointerTG, True, True); 
            dtwm.origKeyboardFocusPolicy = POINTER;
        }
        if (strcmp(string, "explicit") == 0)
        {
            XmToggleButtonGadgetSetState (dtwm.explicitTG, True, True); 
            dtwm.origKeyboardFocusPolicy = EXPLICIT;
        }
        XtFree (string);
    }
    else /* KeyboardFocusPolicy not specified */
    {
        /* set the Dtwm default value - explicit */
        XmToggleButtonGadgetSetState (dtwm.explicitTG, True, True); 
        dtwm.origKeyboardFocusPolicy = EXPLICIT;
    } 

    /* Get FocusAutoRaise value */
    if (status = XrmGetResource (db, "dtwm.focusAutoRaise",
                                     "Dtwm.FocusAutoRaise",
                                     &str_type_return, &value_return))
    {
        /* make local copy of string */
        string = (char *) XtMalloc( value_return.size );
        strcpy (string, value_return.addr);

        /* convert to lower case */
        _DtWmParseToLower((unsigned char *)string);

        dtwm.origFocusAutoRaise =                
               (strcmp(string, "true") ? False : True); 
        XmToggleButtonGadgetSetState (dtwm.autoRaiseTG, 
               dtwm.origFocusAutoRaise, True);

        XtFree (string);
    }
    else /* FocusAutoRaise not specified */
    {
        /* set the Dtwm default value: 
         *  True when keyboardFocusPolicy is explicit 
         *  False when keyboardFocusPolicy is pointer
         */
        dtwm.origFocusAutoRaise =   
                ((dtwm.origKeyboardFocusPolicy == EXPLICIT) ? True : False); 
        XmToggleButtonGadgetSetState (dtwm.autoRaiseTG, 
                dtwm.origFocusAutoRaise, True);
    }

    /* Get SecStack value from secondaries OnTop resource*/
    if (status = XrmGetResource (db, "dtwm.secondariesOnTop",
                                     "Dtwm.secondariesOnTop",
                                     &str_type_return, &value_return))
    {
        /* make local copy of string */
        string = (char *) XtMalloc( value_return.size );
        strcpy (string, value_return.addr);

        /* convert to lower case */
        _DtWmParseToLower((unsigned char *)string);

        dtwm.origSecStack =                
               (strcmp(string, "true") ? False : True); 
        XmToggleButtonGadgetSetState (dtwm.secStackTG, 
               !dtwm.origSecStack, True);

        XtFree (string);
    }
    else /* SecStack resource not specified */
      {
#ifdef sun
	dtwm.origSecStack = False;
	XmToggleButtonGadgetSetState (dtwm.secStackTG, 
				      !dtwm.origSecStack, False);
#else
	dtwm.origSecStack = True;
	XmToggleButtonGadgetSetState (dtwm.secStackTG, 
				      !dtwm.origSecStack, True);
#endif
      }
    /* Get UseIconBox value */
    if (status = XrmGetResource (db, "dtwm.useIconBox",
                                 "Dtwm.UseIconBox",
                                 &str_type_return, &value_return))
    {
        /* make local copy of string */
        string = (char *) XtMalloc( value_return.size );
        strcpy (string, value_return.addr);

        /* convert to lower case */
        _DtWmParseToLower((unsigned char *)string);

        dtwm.origUseIconBox =                
              (strcmp(string, "true") ? False : True); 
        if (dtwm.origUseIconBox)
            XmToggleButtonGadgetSetState (dtwm.iconBoxTG, True, True); 
        else
            XmToggleButtonGadgetSetState (dtwm.desktopTG, True, True); 

        XtFree (string);
    }                                 
    else /* UseIconBox not specified */
    {
        /* set the Dtwm default value - False, desktop - True*/
        dtwm.origUseIconBox =  False;
        XmToggleButtonGadgetSetState (dtwm.desktopTG, True, True); 
    }

    /* Get MoveOpaque value */
    if (status = XrmGetResource (db, "dtwm.moveOpaque",
                                     "Dtwm.MoveOpaque",
                                     &str_type_return, &value_return))
    {
        /* make local copy of string */
        string = (char *) XtMalloc( value_return.size );
        strcpy (string, value_return.addr);

        /* convert to lower case */
        _DtWmParseToLower((unsigned char *)string);

        dtwm.origMoveOpaque =               
               (strcmp(string, "true") ? False : True); 
        XmToggleButtonGadgetSetState (dtwm.moveOpaqueTG, 
               dtwm.origMoveOpaque, True);

        XtFree (string);
    }
    else /* MoveOpaque not specified */
    {
        /* set the Dtwm default value: False */

        dtwm.origMoveOpaque =  False; 
        XmToggleButtonGadgetSetState (dtwm.moveOpaqueTG, 
                dtwm.origMoveOpaque, True);
    }

}
コード例 #30
0
ファイル: xclip.c プロジェクト: svn2github/foo
/* Use XrmParseCommand to parse command line options to option variable */
static void doOptMain (int argc, char *argv[])
{
	/* Initialise resource manager and parse options into database */
	XrmInitialize();
	XrmParseCommand(
		&opt_db,
		opt_tab,
		sizeof(opt_tab) / sizeof(opt_tab[0]),
		XC_NAME,
		&argc,
		argv
	);
  
	/* set output level */
	if (
		XrmGetResource(
			opt_db,
			"xclip.olevel",
			"Xclip.Olevel",
			&rec_typ,
			&rec_val
		)
	)
	{
		/* set verbose flag according to option */
		if (strcmp(rec_val.addr, "S") == 0)
			fverb = OSILENT;
		if (strcmp(rec_val.addr, "Q") == 0)
			fverb = OQUIET;
		if (strcmp(rec_val.addr, "V") == 0)
			fverb = OVERBOSE;
	}
  
	/* set direction flag (in or out) */
	if (
		XrmGetResource(
			opt_db,
			"xclip.direction",
			"Xclip.Direction",
			&rec_typ,
			&rec_val
		)
	)
	{
		if (strcmp(rec_val.addr, "I") == 0)
			fdiri = T;
		if (strcmp(rec_val.addr, "O") == 0)
			fdiri = F;
	}
  
	/* set filter mode */
	if (
		XrmGetResource(
			opt_db,
			"xclip.filter",
			"Xclip.Filter",
			&rec_typ,
			&rec_val
		)
	)
	{
		/* filter mode only allowed in silent mode */
		if (fverb == OSILENT)
			ffilt = T;
	}
  
	/* check for -help and -version */
	if (
		XrmGetResource(
			opt_db,
			"xclip.print",
			"Xclip.Print",
			&rec_typ,
			&rec_val
		)
	)
	{
		if (strcmp(rec_val.addr, "H") == 0)
			prhelp(argv[0]);
		if (strcmp(rec_val.addr, "V") == 0)
			prversion();
	}
  
	/* check for -display */
	if (
		XrmGetResource(
			opt_db,
			"xclip.display",
			"Xclip.Display",
			&rec_typ,
			&rec_val
		)
	)
	{
		sdisp = rec_val.addr;
		if (fverb == OVERBOSE)	/* print in verbose mode only */
			fprintf(stderr, "Display: %s\n", sdisp);
	}
  
	/* check for -loops */
	if (
		XrmGetResource(
			opt_db,
			"xclip.loops",
			"Xclip.Loops",
			&rec_typ,
			&rec_val
		)
	)
	{
		sloop = atoi(rec_val.addr);
		if (fverb == OVERBOSE)	/* print in verbose mode only */
			fprintf(stderr, "Loops: %i\n", sloop);
	}

	/* Read remaining options (filenames) */
	while ( (fil_number + 1) < argc )
	{
		if (fil_number > 0)
		{
			fil_names = xcrealloc(
				fil_names,
				(fil_number + 1) * sizeof(char*)
			);
		} else
		{
			fil_names = xcmalloc(sizeof(char*));
		}
		fil_names[fil_number] = argv[fil_number + 1];
		fil_number++;
	}
}