static XrmDatabase InitDefaults( Display *dpy) /* display for defaults.... */ { XrmDatabase userdb; XrmDatabase xdb; char fname[PATH_MAX]; /* longer than any conceivable size */ char *xenv; XrmInitialize(); /* * See lib/Xt/Initialize.c * * First, get the defaults from the server; if none, then load from * ~/.Xdefaults. Next, if there is an XENVIRONMENT environment variable, * then load that file. */ if (dpy->xdefaults == NULL) { #ifdef _MSC_VER const char *slashDotXdefaults = ".Xdefaults"; #else const char *slashDotXdefaults = "/.Xdefaults"; #endif (void) GetHomeDir (fname, PATH_MAX - strlen (slashDotXdefaults) - 1); (void) strcat (fname, slashDotXdefaults); xdb = XrmGetFileDatabase (fname); } else { xdb = XrmGetStringDatabase(dpy->xdefaults); } if (!(xenv = getenv ("XENVIRONMENT"))) { #ifdef _MSC_VER const char *slashDotXdefaultsDash = ".Xdefaults-"; #else const char *slashDotXdefaultsDash = "/.Xdefaults-"; #endif int len; (void) GetHomeDir (fname, PATH_MAX - strlen (slashDotXdefaultsDash) - 1); (void) strcat (fname, slashDotXdefaultsDash); len = strlen (fname); (void) _XGetHostname (fname+len, PATH_MAX-len); xenv = fname; } userdb = XrmGetFileDatabase (xenv); XrmMergeDatabases (userdb, &xdb); return (xdb); #ifdef old if (fname[0] != '\0') userdb = XrmGetFileDatabase(fname); xdb = XrmGetStringDatabase(dpy->xdefaults); XrmMergeDatabases(userdb, &xdb); return xdb; #endif }
// 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; }
void XsComponent::_setResources (Widget w, const String *resources) { assert (w != 0); XrmDatabase rdb = 0; const int bufSize = 200; char buffer[bufSize]; int loop; // Create an empty resource database rdb = XrmGetStringDatabase (""); // Add the component resources loop = 0; while (resources[loop] != 0) { sprintf (buffer, "*%s%s\n", _name, resources[loop++]); assert (strlen (buffer) < bufSize); XrmPutLineResource (&rdb, buffer); } // Merge these resources into the database if (rdb != 0) { XrmDatabase db = XtDatabase (XtDisplay (w)); XrmCombineDatabase (rdb, &db, FALSE); } }
/* * Not yet used but may be useful. * */ void wxSetDefaultResources (const Widget w, const char **resourceSpec, const char *name) { int i; Display *dpy = XtDisplay (w); // Retrieve the display pointer XrmDatabase rdb = NULL; // A resource data base // Create an empty resource database rdb = XrmGetStringDatabase (""); // Add the Component resources, prepending the name of the component i = 0; while (resourceSpec[i] != NULL) { char buf[1000]; sprintf (buf, "*%s%s", name, resourceSpec[i++]); XrmPutLineResource (&rdb, buf); } // Merge them into the Xt database, with lowest precendence if (rdb) { #if (XlibSpecificationRelease>=5) XrmDatabase db = XtDatabase (dpy); XrmCombineDatabase (rdb, &db, False); #else XrmMergeDatabases (dpy->db, &rdb); dpy->db = rdb; #endif } }
void aX_open_second_disp(char *display_name, aX_default_resources *defres) { char *disp_res; XrmDatabase serverDB; if((defres->disp = XOpenDisplay(display_name)) == NULL) { fprintf(stderr, "%s: aX_open_second_disp: cannot connect to X server %s\n", prog_name, XDisplayName(display_name)); exit(-1); } disp_res = XResourceManagerString(defres->disp); if(disp_res) serverDB = XrmGetStringDatabase(disp_res); else serverDB = NULL; XrmMergeDatabases(serverDB, &rDB); get_def_res(defres); add_disp(defres); }
void MotifUI::SetDefaultResources(const Widget, const String *resources) { XrmDatabase rdb = NULL; int i; rdb = XrmGetStringDatabase(""); i = 0; while (resources[i]) { char *buf = new char[1000]; sprintf(buf, "%s%s", _name, resources[i]); XrmPutLineResource(&rdb, buf); i++; delete [] buf; } if (rdb) { XrmMergeDatabases(XtDatabase(display), &rdb); XrmSetDatabase(display, rdb); } }
static XrmDatabase get_database( void) { XrmDatabase db = XrmGetStringDatabase( ""); char filename[PATH_MAX]; char *c; char *resource_data = XResourceManagerString( DISP); if ( resource_data) { XrmCombineDatabase( XrmGetStringDatabase( resource_data), &db, false); } else { c = getenv( "HOME"); if (!c) c = ""; snprintf( filename, PATH_MAX, "%s/.Xdefaults", c); XrmCombineFileDatabase( filename, &db, false); } return db; }
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); }
/* ** CreatePreferencesDatabase ** ** Process a preferences file and the command line options pertaining to ** the X resources used to set those preferences. Create an X database ** of the results. The reason for this odd set of functionality is ** to process command line options before XtDisplayInitialize reads them ** into the application database that the toolkit attaches to the display. ** This allows command line arguments to properly override values specified ** in the preferences file. ** ** fileName Name only of the preferences file to be found ** in the user's home directory ** appName Application name to use in reading the preference ** resources ** opTable Xrm command line option table for the resources ** used in the preferences file ONLY. Command line ** options for other X resources should be processed ** by XtDisplayInitialize. ** nOptions Number of items in opTable ** argcInOut Address of argument count. This will be altered ** to remove the command line options that are ** recognized in the option table. ** argvInOut Argument vector. Will be altered as argcInOut. */ XrmDatabase CreatePreferencesDatabase(const char *fullName, const char *appName, XrmOptionDescList opTable, int nOptions, unsigned int *argcInOut, char **argvInOut) { XrmDatabase db; int argcCopy; char **argvCopy; char *fileString; static XrmOptionDescRec xrmOnlyTable[] = {{"-xrm", NULL, XrmoptionResArg, (caddr_t)NULL}}; /* read the preferences file into an X database. On failure prefDB will be NULL. */ if (NULL == fullName) { db = NULL; } else { fileString = ReadAnyTextFile(fullName, False); if (NULL == fileString) { db = NULL; } else { char* rsrcName; db = XrmGetStringDatabase(fileString); XtFree(fileString); /* Add a resource to the database which remembers that the file is read, so that NEdit will know it. */ rsrcName = (char*) XtMalloc(strlen(appName) + 14); sprintf(rsrcName, "%s.prefFileRead", appName); XrmPutStringResource(&db, rsrcName, "True"); XtFree(rsrcName); } } /* parse the command line, storing results in the preferences database */ XrmParseCommand(&db, opTable, nOptions, appName, (int *)argcInOut, argvInOut); /* process -xrm (resource setting by resource name) arguments so those pertaining to preference resources will be included in the database. Don't remove -xrm arguments from the argument vector, however, so XtDisplayInitialize can still read the non-preference resources */ argvCopy = (char**)XtMalloc(sizeof(char *) * *argcInOut); memcpy(argvCopy, argvInOut, sizeof(char *) * *argcInOut); argcCopy = *argcInOut; XrmParseCommand(&db, xrmOnlyTable, XtNumber(xrmOnlyTable), appName, &argcCopy, argvCopy); XtFree((char *)argvCopy); return db; }
void wxXMergeDatabases (wxApp * theApp, Display * display) { XrmDatabase homeDB, serverDB, applicationDB; char filenamebuf[1024]; char *filename = &filenamebuf[0]; char *environment; wxString classname = theApp->GetClassName(); char name[256]; (void) strcpy (name, "/usr/lib/X11/app-defaults/"); (void) strcat (name, classname.c_str()); /* Get application defaults file, if any */ applicationDB = XrmGetFileDatabase (name); (void) XrmMergeDatabases (applicationDB, &wxResourceDatabase); /* Merge server defaults, created by xrdb, loaded as a property of the root * window when the server initializes and loaded into the display * structure on XOpenDisplay; * if not defined, use .Xdefaults */ if (XResourceManagerString (display) != NULL) { serverDB = XrmGetStringDatabase (XResourceManagerString (display)); } else { (void) GetIniFile (filename, NULL); serverDB = XrmGetFileDatabase (filename); } XrmMergeDatabases (serverDB, &wxResourceDatabase); /* Open XENVIRONMENT file, or if not defined, the .Xdefaults, * and merge into existing database */ if ((environment = getenv ("XENVIRONMENT")) == NULL) { size_t len; environment = GetIniFile (filename, NULL); len = strlen (environment); wxString hostname = wxGetHostName(); if ( !!hostname ) strncat(environment, hostname, 1024 - len); } homeDB = XrmGetFileDatabase (environment); XrmMergeDatabases (homeDB, &wxResourceDatabase); }
static void CombineUserDefaults( Display *dpy, XrmDatabase *pdb) { char *slashDotXdefaults = "/.Xdefaults"; char *dpy_defaults = XResourceManagerString(dpy); if (dpy_defaults) { XrmCombineDatabase(XrmGetStringDatabase(dpy_defaults), pdb, False); } else { char filename[PATH_MAX]; (void) GetRootDirName(filename, PATH_MAX - strlen (slashDotXdefaults) - 1); (void) strcat(filename, slashDotXdefaults); (void)XrmCombineFileDatabase(filename, pdb, False); } }
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; }
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; } }
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); }
void XsComponent::_setResources (Widget w, const String *resources) { assert (w != 0); XrmDatabase rdb = 0; const int bufSize = 200; char buffer[bufSize]; int loop; // Create an empty resource database rdb = XrmGetStringDatabase (""); // Add the component resources loop = 0; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (resources[loop] != 0) { sprintf (buffer, "*%s%s\n", _name, resources[loop++]); assert (strlen (buffer) < bufSize); XrmPutLineResource (&rdb, buffer); } // Merge these resources into the database if (rdb != 0) { XrmDatabase db = XtDatabase (XtDisplay (w)); XrmCombineDatabase (rdb, &db, FALSE); } }
Bool InitializeOptionsDatabase(void) { static int first = 1; static Bool result = True; if (first) { XrmQuark names[2]; XrmQuark classes[2]; first = 0; XrmInitialize(); if ((options_xrm = XrmGetFileDatabase(Options)) == (XrmDatabase)0) { fprintf(stderr, "Cannot open '%s' database.\n", Options); return (False); } /* rebuild database, using only lowercase characters */ names[0] = classes[0] = names[1] = classes[1] = NULLQUARK; (void)XrmEnumerateDatabase(options_xrm, (XrmNameList)&names, (XrmClassList)&classes, XrmEnumAllLevels, EnumDatabase, NULL); /* free previous database, as it is not guaranteed to be * "case insensitive" */ XrmDestroyDatabase(options_xrm); /* create case insensitive database by making everything lowercase */ if (rebuild_xrm.string == NULL || (options_xrm = XrmGetStringDatabase(rebuild_xrm.string)) == (XrmDatabase)0) { fprintf(stderr, "Cannot rebuild '%s' database.\n", Options); XtFree(rebuild_xrm.string); return (False); } XtFree(rebuild_xrm.string); } return (result); }
void mergeDatabases(void) { /* using global rDB dsply */ XrmDatabase homeDB,serverDB,applicationDB; char filenamebuf[1024]; char *filename = &filenamebuf[0]; char *classname = "Axiom"; char name[255]; (void) XrmInitialize(); (void) strcpy(name, "/usr/lib/X11/app-defaults/"); (void) strcat(name, classname); applicationDB = XrmGetFileDatabase(name); (void) XrmMergeDatabases(applicationDB, &rDB); if (XResourceManagerString(dsply) != NULL) serverDB = XrmGetStringDatabase(XResourceManagerString(dsply)); else { (void) strcpy(filename,getenv("HOME")); (void) strcat(filename,"/.Xdefaults"); serverDB = XrmGetFileDatabase(filename); } XrmMergeDatabases(serverDB,&rDB); if ( getenv ("XENVIRONMENT") == NULL) { int len; (void) strcpy(filename,getenv("HOME")); (void) strcat(filename,"/.Xdefaults-"); len = strlen(filename); (void) gethostname(filename+len,1024-len); } else (void) strcpy (filename,getenv ("XENVIRONMENT")); homeDB = XrmGetFileDatabase(filename); XrmMergeDatabases(homeDB,&rDB); }
/* 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); } }
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; }
XrmDatabase XtScreenDatabase( Screen *screen) { int scrno; Bool doing_def; XrmDatabase db, olddb; XtPerDisplay pd; Status do_fallback; char *scr_resources; Display *dpy = DisplayOfScreen(screen); DPY_TO_APPCON(dpy); LOCK_APP(app); LOCK_PROCESS; if (screen == DefaultScreenOfDisplay(dpy)) { scrno = DefaultScreen(dpy); doing_def = True; } else { scrno = XScreenNumberOfScreen(screen); doing_def = False; } pd = _XtGetPerDisplay(dpy); if ((db = pd->per_screen_db[scrno])) { UNLOCK_PROCESS; UNLOCK_APP(app); return (doing_def ? XrmGetDatabase(dpy) : db); } scr_resources = XScreenResourceString(screen); if (ScreenCount(dpy) == 1) { db = pd->cmd_db; pd->cmd_db = NULL; } else { db = CopyDB(pd->cmd_db); } { /* Environment defaults */ char filenamebuf[PATH_MAX]; char *filename; if (!(filename = getenv("XENVIRONMENT"))) { int len; #ifdef __MINGW32__ const char *slashDotXdefaultsDash = "/Xdefaults-"; #else const char *slashDotXdefaultsDash = "/.Xdefaults-"; #endif (void) GetRootDirName(filename = filenamebuf, PATH_MAX - strlen (slashDotXdefaultsDash) - 1); (void) strcat(filename, slashDotXdefaultsDash); len = strlen(filename); GetHostname (filename+len, PATH_MAX-len); } (void)XrmCombineFileDatabase(filename, &db, False); } if (scr_resources) { /* Screen defaults */ XrmCombineDatabase(XrmGetStringDatabase(scr_resources), &db, False); XFree(scr_resources); } /* Server or host defaults */ if (!pd->server_db) CombineUserDefaults(dpy, &db); else { (void) XrmCombineDatabase(pd->server_db, &db, False); pd->server_db = NULL; } if (!db) db = XrmGetStringDatabase(""); pd->per_screen_db[scrno] = db; olddb = XrmGetDatabase(dpy); /* set database now, for XtResolvePathname to use */ XrmSetDatabase(dpy, db); CombineAppUserDefaults(dpy, &db); do_fallback = 1; { /* System app-defaults */ char *filename; if ((filename = XtResolvePathname(dpy, "app-defaults", NULL, NULL, NULL, NULL, 0, NULL))) { do_fallback = !XrmCombineFileDatabase(filename, &db, False); XtFree(filename); } } /* now restore old database, if need be */ if (!doing_def) XrmSetDatabase(dpy, olddb); if (do_fallback && pd->appContext->fallback_resources) { /* Fallback defaults */ XrmDatabase fdb = NULL; String *res; for (res = pd->appContext->fallback_resources; *res; res++) XrmPutLineResource(&fdb, *res); (void)XrmCombineDatabase(fdb, &db, False); } UNLOCK_PROCESS; UNLOCK_APP(app); return db; }
void aX_open_disp(aX_options *useropt, int useroptlen, int *argcp, char *argv[], aX_default_resources *defres) { XrmValue value; char *str_type; char *disp_res; char *environment; char *display_name = NULL; char filename[MAX_FILENAME_LEN]; int i; XrmDatabase commandlineDB = NULL, usercommandlineDB = NULL; XrmDatabase homeDB, serverDB, applicationDB; /* if(disp_start.next_disp != NULL) { fprintf(stderr, "aX_open_disp: Cannot open first display twice.\n"); exit(-1); } */ XrmInitialize(); class_name[0] = '\0'; class_name[MAX_CLASS_NAME_LEN] = '\0'; if(defres->class_name != NULL) strncpy(class_name, defres->class_name, MAX_CLASS_NAME_LEN); fill_event_info(); for(i = 1; i < *argcp; i++) if(strcmp(argv[i], "-name") == 0 && ++i < *argcp){ defres->prog_name = argv[i]; break; } prog_name[0] = '\0'; prog_name[MAX_PROG_NAME_LEN] = '\0'; if(defres->prog_name != NULL) strncpy(prog_name, defres->prog_name, MAX_PROG_NAME_LEN); else strncpy(prog_name, argv[0], MAX_PROG_NAME_LEN); defres->prog_name = prog_name; XrmParseCommand(&commandlineDB, (XrmOptionDescRec *) opTable, opTableEntries, prog_name, argcp, argv); if(useropt != NULL) XrmParseCommand(&usercommandlineDB, (XrmOptionDescRec *) useropt, useroptlen, prog_name, argcp, argv); else usercommandlineDB = NULL; /* if(*argcp != 1) { fprintf(stderr, "%s: aX_open_disp: Unrecognised options in command line!\n", prog_name); exit(-1); } */ if(XrmGetResource(commandlineDB, pname(".display"), pclass(".Display"), &str_type, &value)) display_name = (char *) value.addr; if((defres->disp = XOpenDisplay(display_name)) == NULL) { fprintf(stderr, "%s: aX_open_disp: cannot connect to X server %s\n", prog_name, XDisplayName(display_name)); exit(-1); } applicationDB = XrmGetFileDatabase( addstr("/usr/lib/X11/app-defaults/", class_name, filename, MAX_FILENAME_LEN)); /* if(defres->disp->xdefaults) serverDB = XrmGetStringDatabase(defres->disp->xdefaults); else serverDB = NULL; */ disp_res = XResourceManagerString(defres->disp); if(disp_res) serverDB = XrmGetStringDatabase(disp_res); else serverDB = NULL; if((environment = getenv("XENVIRONMENT")) != NULL) homeDB = XrmGetFileDatabase(environment); else homeDB = NULL; XrmMergeDatabases(applicationDB, &rDB); XrmMergeDatabases(serverDB, &rDB); XrmMergeDatabases(homeDB, &rDB); XrmMergeDatabases(commandlineDB, &rDB); XrmMergeDatabases(usercommandlineDB, &rDB); get_def_res(defres); add_disp(defres); }
/* ARGSUSED */ static void DisplayInitialize( Widget requested_widget, Widget new_widget, ArgList args, Cardinal *num_args ) { XmDisplay xmDisplay = (XmDisplay)new_widget; int dummy1, dummy2; XContext context; xmDisplay->display.shellCount = 0; xmDisplay->display.numModals = 0; xmDisplay->display.modals = NULL; xmDisplay->display.maxModals = 0; xmDisplay->display.userGrabbed = False; xmDisplay->display.activeDC = NULL; xmDisplay->display.dsm = (XmDropSiteManagerObject) NULL; xmDisplay->display.proxyWindow = _XmGetDragProxyWindow(XtDisplay(xmDisplay)); _XmInitByteOrderChar(); xmDisplay->display.xmim_info = NULL; xmDisplay->display.displayInfo = (XtPointer) XtNew(XmDisplayInfo); ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->SashCursor = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->TearOffCursor = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->UniqueStamp = 0L; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->destinationWidget= (Widget)NULL; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.pane = (Widget *)NULL; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.pane_list_size = 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->excParentPane.num_panes= 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->resetFocusFlag = 0; ((XmDisplayInfo *)(xmDisplay->display.displayInfo))->traversal_in_progress= FALSE; xmDisplay->display.displayHasShapeExtension = XShapeQueryExtension(XtDisplay(xmDisplay), &dummy1, &dummy2); /* Handle dynamic default of receiver protocol style */ if (xmDisplay->display.dragReceiverProtocolStyle == INVALID_PROTOCOL_VALUE) { if (xmDisplay->display.displayHasShapeExtension) xmDisplay->display.dragReceiverProtocolStyle = XmDRAG_PREFER_DYNAMIC; else xmDisplay->display.dragReceiverProtocolStyle = XmDRAG_PREFER_PREREGISTER; } _XmVirtKeysInitialize (new_widget); /* Solaris 2.6 Motif diff bug #4085003 4 lines */ #ifdef SUN_MOTIF _XmGetKPKeysymToKeycodeList(new_widget); _XmGetModifierMapping(new_widget); #endif /* SUN_MOTIF */ _XmProcessLock(); if (displayContext == 0) displayContext = XUniqueContext(); context = displayContext; _XmProcessUnlock(); if (! XFindContext(XtDisplay(xmDisplay), None, context, (char **) &xmDisplay)) { /* * There's one already created for this display. * What should we do? If we destroy the previous one, we may * wreak havoc with shell modality and screen objects. BUT, * Xt doesn't really give us a way to abort a create. We'll * just let the new one dangle. */ XmeWarning((Widget) xmDisplay, MESSAGE1); } else { XSaveContext(XtDisplayOfObject((Widget)xmDisplay), None, context, (char *)xmDisplay); } if (xmDisplay->display.enable_multi_key_bindings) { Display * display = XtDisplay(new_widget); int i, num_screens = ScreenCount(display); XrmDatabase new_db; for (i = 0; i < num_screens; i++) { Screen * screen = ScreenOfDisplay(display, i); XrmDatabase db = XtScreenDatabase(screen); new_db = XrmGetStringDatabase(_XmDisplay_baseTranslations); XrmCombineDatabase(new_db, &db, False); } } }
int main(int argc, char **argv) { int opt; struct option longopts[] = { {"help", no_argument, NULL, 'h'}, {"modules", no_argument, NULL, 'm'}, {"auth", required_argument, NULL, 'a'}, {"bg", required_argument, NULL, 'b'}, {"cursor", required_argument, NULL, 'c'}, {"input", required_argument, NULL, 'i'}, {0, 0, 0, 0}, }; Display *display; struct aModules modules; int retval; const char *args_auth = NULL; const char *args_background = NULL; const char *args_cursor = NULL; const char *args_input = NULL; /* set-up default modules */ modules.auth = alock_modules_auth[0]; modules.background = alock_modules_background[0]; modules.cursor = alock_modules_cursor[0]; modules.input = alock_modules_input[0]; #if WITH_XBLIGHT modules.backlight = -1; #endif /* parse options */ while ((opt = getopt_long_only(argc, argv, "hma:b:c:i:", longopts, NULL)) != -1) switch (opt) { case 'h': printf("%s [-help] [-modules] [-auth type:options] [-bg type:options]" " [-cursor type:options] [-input type:options]\n", argv[0]); return EXIT_SUCCESS; case 'm': { /* list available modules */ struct aModuleAuth **ia; struct aModuleBackground **ib; struct aModuleCursor **ic; struct aModuleInput **ii; printf("authentication modules:\n"); for (ia = alock_modules_auth; *ia; ++ia) printf(" %s\n", (*ia)->m.name); printf("background modules:\n"); for (ib = alock_modules_background; *ib; ++ib) printf(" %s\n", (*ib)->m.name); printf("cursor modules:\n"); for (ic = alock_modules_cursor; *ic; ++ic) printf(" %s\n", (*ic)->m.name); printf("input modules:\n"); for (ii = alock_modules_input; *ii; ++ii) printf(" %s\n", (*ii)->m.name); return EXIT_SUCCESS; } case 'a': { /* authentication module */ struct aModuleAuth **i; for (i = alock_modules_auth; *i; ++i) if (strstr(optarg, (*i)->m.name) == optarg) { args_auth = optarg; modules.auth = *i; break; } if (*i == NULL) { fprintf(stderr, "alock: authentication module `%s` not found\n", optarg); return EXIT_FAILURE; } break; } case 'b': { /* background module */ struct aModuleBackground **i; for (i = alock_modules_background; *i; ++i) if (strstr(optarg, (*i)->m.name) == optarg) { args_background = optarg; modules.background = *i; break; } if (*i == NULL) { fprintf(stderr, "alock: background module `%s` not found\n", optarg); return EXIT_FAILURE; } break; } case 'c': { /* cursor module */ struct aModuleCursor **i; for (i = alock_modules_cursor; *i; ++i) if (strstr(optarg, (*i)->m.name) == optarg) { args_cursor = optarg; modules.cursor = *i; break; } if (*i == NULL) { fprintf(stderr, "alock: cursor module `%s` not found\n", optarg); return EXIT_FAILURE; } break; } case 'i': { /* input module */ struct aModuleInput **i; for (i = alock_modules_input; *i; ++i) if (strstr(optarg, (*i)->m.name) == optarg) { args_input = optarg; modules.input = *i; break; } if (*i == NULL) { fprintf(stderr, "alock: input module `%s` not found\n", optarg); return EXIT_FAILURE; } break; } default: fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); return EXIT_FAILURE; } /* required for correct input handling */ setlocale(LC_ALL, ""); if ((display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "error: unable to connect to the X display\n"); return EXIT_FAILURE; } /* make sure, that only one instance of alock is running */ if (registerInstance(display)) { fprintf(stderr, "error: another instance seems to be running\n"); XCloseDisplay(display); return EXIT_FAILURE; } #if WITH_DUNST /* pause notification daemon */ system("pkill -x -SIGUSR1 dunst"); #endif { /* try to initialize selected modules */ int rv = 0; XrmInitialize(); const char *data = XResourceManagerString(display); XrmDatabase xrdb = XrmGetStringDatabase(data != NULL ? data : ""); modules.auth->m.loadxrdb(xrdb); modules.background->m.loadxrdb(xrdb); modules.cursor->m.loadxrdb(xrdb); modules.input->m.loadxrdb(xrdb); #if WITH_XBLIGHT XrmValue value; char *type; if (XrmGetResource(xrdb, "alock.backlight", "ALock.Backlight", &type, &value) && strcmp(value.addr, "true") == 0) modules.backlight = getBacklightBrightness(); #endif /* WITH_XBLIGHT */ XrmDestroyDatabase(xrdb); modules.auth->m.loadargs(args_auth); modules.background->m.loadargs(args_background); modules.cursor->m.loadargs(args_cursor); modules.input->m.loadargs(args_input); if (modules.auth->m.init(display)) { fprintf(stderr, "alock: failed init of [%s] with [%s]\n", modules.auth->m.name, args_auth); rv |= 1; } #if ENABLE_PASSWD /* We can be installed setuid root to support shadow passwords, * and we don't need root privileges any longer. --marekm */ if (setuid(getuid()) != 0) perror("alock: root privilege drop failed"); #endif if (modules.background->m.init(display)) { fprintf(stderr, "alock: failed init of [%s] with [%s]\n", modules.background->m.name, args_background); rv |= 1; } if (modules.cursor->m.init(display)) { fprintf(stderr, "alock: failed init of [%s] with [%s]\n", modules.cursor->m.name, args_cursor); rv |= 1; } if (modules.input->m.init(display)) { fprintf(stderr, "alock: failed init of [%s] with [%s]\n", modules.input->m.name, args_input); rv |= 1; } if (rv) /* initialization failed */ goto return_failure; } #if HAVE_XMISC int xf86misc_major = -1; int xf86misc_minor = -1; if (XF86MiscQueryVersion(display, &xf86misc_major, &xf86misc_minor) == True) { if (xf86misc_major >= 0 && xf86misc_minor >= 5 && XF86MiscSetGrabKeysState(display, False) == MiscExtGrabStateLocked) { fprintf(stderr, "error: unable to disable Xorg hotkeys to remove grabs\n"); goto return_failure; } fprintf(stderr, "info: disabled AllowDeactivateGrabs and AllowClosedownGrabs\n"); } #endif /* HAVE_XMISC */ /* raise our background window and grab input, if this action has failed, * we are not able to lock the screen, then we're f****d... */ if (lockDisplay(display, &modules)) goto return_failure; debug("entering main event loop"); eventLoop(display, &modules); retval = EXIT_SUCCESS; goto return_success; return_failure: retval = EXIT_FAILURE; return_success: #if HAVE_XMISC if (xf86misc_major >= 0 && xf86misc_minor >= 5) { XF86MiscSetGrabKeysState(display, True); XFlush(display); } #endif modules.auth->m.free(); modules.cursor->m.free(); modules.input->m.free(); modules.background->m.free(); unregisterInstance(display); XCloseDisplay(display); #if WITH_DUNST /* resume notification daemon */ system("pkill -x -SIGUSR2 dunst"); #endif return retval; }
static void Get_file_defaults(XrmDatabase *rDBptr, char *myName, char *myClass) { #ifdef VMS #define MAXPATHLEN 1024 #endif int len; char *ptr, *lang = getenv("LANG"), *home = getenv("HOME"), path[MAXPATHLEN]; XrmDatabase tmpDB; sprintf(path, "%s%s", LIBDIR, myClass); *rDBptr = XrmGetFileDatabase(path); #ifdef VMS /* * None of the paths generated will be valid VMS file names. */ tmpDB = XrmGetFileDatabase("SYS$LOGIN:decw$xdefaults.dat"); XrmMergeDatabases(tmpDB, rDBptr); tmpDB = XrmGetFileDatabase("DECW$USER_DEFAULTS:xpilot.dat"); XrmMergeDatabases(tmpDB, rDBptr); #else if (lang != NULL) { sprintf(path, "/usr/lib/X11/%s/app-defaults/%s", lang, myClass); if (access(path, 0) == -1) { sprintf(path, "/usr/lib/X11/app-defaults/%s", myClass); } } else { sprintf(path, "/usr/lib/X11/app-defaults/%s", myClass); } tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); if ((ptr = getenv("XUSERFILESEARCHPATH")) != NULL) { sprintf(path, "%s/%s", ptr, myClass); tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } else if ((ptr = getenv("XAPPLRESDIR")) != NULL) { if (lang != NULL) { sprintf(path, "%s/%s/%s", ptr, lang, myClass); if (access(path, 0) == -1) { sprintf(path, "%s/%s", ptr, myClass); } } else { sprintf(path, "%s/%s", ptr, myClass); } tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } else if (home != NULL) { if (lang != NULL) { sprintf(path, "%s/app-defaults/%s/%s", home, lang, myClass); if (access(path, 0) == -1) { sprintf(path, "%s/app-defaults/%s", home, myClass); } } else { sprintf(path, "%s/app-defaults/%s", home, myClass); } tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } if ((ptr = XResourceManagerString(dpy)) != NULL) { tmpDB = XrmGetStringDatabase(ptr); XrmMergeDatabases(tmpDB, rDBptr); } else if (home != NULL) { sprintf(path, "%s/.Xdefaults", home); tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } if ((ptr = getenv("XENVIRONMENT")) != NULL) { tmpDB = XrmGetFileDatabase(ptr); XrmMergeDatabases(tmpDB, rDBptr); } else if (home != NULL) { sprintf(path, "%s/.Xdefaults-", home); len = strlen(path); gethostname(&path[len], sizeof path - len); path[sizeof path - 1] = '\0'; tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } if (home != NULL) { sprintf(path, "%s/.xpilotrc", home); tmpDB = XrmGetFileDatabase(path); XrmMergeDatabases(tmpDB, rDBptr); } #endif }