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); }
static void revert_prefs_cb(XtPointer arg) { struct topic_info *info = (struct topic_info *)arg; struct prefs_choice *prefs = (struct prefs_choice *)info->data; size_t i; /* pop down dependent windows */ TRACE_GUI((stderr, "window count: %lu", (unsigned long)prefs->depwin_cnt)); for (i = 0; i < prefs->depwin_cnt; i++) { TRACE_GUI((stderr, "popping down %lu: %p", (unsigned long)i, (void *)(prefs->depwin[i]))); if (XtIsRealized(prefs->depwin[i])) { XtCallCallbacks(prefs->depwin[i], XmNcancelCallback, NULL); XSync(DISP, True); /* wait for server to catch up */ if (XtIsRealized(prefs->depwin[i])) { TRACE_GUI((stderr, "calling XmNokCallback of %lu: %p", (unsigned long)i, (void *)(prefs->depwin[i]))); XtCallCallbacks(prefs->depwin[i], XmNokCallback, NULL); } } } free(prefs->depwin); prefs->depwin = NULL; prefs->depwin_cnt = 0; if (prefs->db == NULL) { /* callback invoked multiple times, or prefs not changed */ return; } revert_resources(); XrmDestroyDatabase(prefs->db); prefs->db = NULL; }
// 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 Blackbox::timeout(bt::Timer *) { XrmDatabase new_blackboxrc = (XrmDatabase) 0; std::string style = "session.styleFile: "; style += _resource.styleFilename(); XrmPutLineResource(&new_blackboxrc, style.c_str()); XrmDatabase old_blackboxrc = XrmGetFileDatabase(_resource.rcFilename()); XrmMergeDatabases(new_blackboxrc, &old_blackboxrc); XrmPutFileDatabase(old_blackboxrc, _resource.rcFilename()); if (old_blackboxrc) XrmDestroyDatabase(old_blackboxrc); std::for_each(menuTimestamps.begin(), menuTimestamps.end(), bt::PointerAssassin()); menuTimestamps.clear(); std::for_each(screen_list, screen_list + screen_list_count, std::mem_fun(&BScreen::reconfigure)); bt::Font::clearCache(); bt::PixmapCache::clearCache(); bt::Pen::clearCache(); // clear the color cache here to allow the pen cache to deallocate // all unused colors bt::Color::clearCache(); }
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); }
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; }
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; }
void wxFlushResources (void) { char nameBuffer[512]; wxNode *node = wxResourceCache.First (); while (node) { const char *file = node->GetKeyString(); // If file doesn't exist, create it first. (void)GetResourcePath(nameBuffer, file, true); XrmDatabase database = (XrmDatabase) node->Data (); XrmPutFileDatabase (database, nameBuffer); XrmDestroyDatabase (database); wxNode *next = node->Next (); delete node; node = next; } }
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); }
Boolean CloseClientDB(ClientDB clientDBPtr, Boolean writeDB) { ClientDBRec *clientDB = (ClientDBRec *)clientDBPtr; if (clientDB == (ClientDBRec *)NULL) return False; /* Input? */ if (clientDB->openForInput) { XtFree((char *)clientDB->XSMPClients); XtFree((char *)clientDB->proxyClients); XrmDestroyDatabase(clientDB->xrmDB); XtFree((char *)clientDB); return True; } /* Otherwise, output. */ if (writeDB) { /* Close file and remove temp DB. */ fclose(clientDB->xrmDBFile); unlink(clientDB->tmpDBFileName); } else { int rv; /* Close file and remove it; restore original DB. */ fclose(clientDB->xrmDBFile); rv = rename(clientDB->tmpDBFileName, clientDB->xrmDBFileName); } XtFree(clientDB->xrmDBFileName); XtFree(clientDB->tmpDBFileName); XtFree((char *)clientDB); return True; }
void window_subsystem_done( void) { if ( !DISP) return; if ( guts. hostname. value) { XFree( guts. hostname. value); guts. hostname. value = nil; } prima_end_menu(); free_gc_pool(&guts.bitmap_gc_pool); free_gc_pool(&guts.screen_gc_pool); free_gc_pool(&guts.argb_gc_pool); prima_done_color_subsystem(); free( guts. clipboard_formats); XFreeGC( DISP, guts. menugc); prima_gc_ximages(); /* verrry dangerous, very quiet please */ if ( guts.pointer_font) { XFreeFont( DISP, guts.pointer_font); guts.pointer_font = nil; } XCloseDisplay( DISP); DISP = nil; plist_destroy( guts. files); guts. files = nil; XrmDestroyDatabase( guts.db); if (guts.ximages) hash_destroy( guts.ximages, false); if (guts.menu_windows) hash_destroy( guts.menu_windows, false); if (guts.windows) hash_destroy( guts.windows, false); if (guts.clipboards) hash_destroy( guts.clipboards, false); if (guts.clipboard_xfers) hash_destroy( guts.clipboard_xfers, false); prima_cleanup_font_subsystem(); }
/* 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); } }
int /*ARGSUSED*/ XGetErrorDatabaseText( Display *dpy, register _Xconst char *name, register _Xconst char *type, _Xconst char *defaultp, char *buffer, int nbytes) { static XrmDatabase db = NULL; XrmString type_str; XrmValue result; char temp[BUFSIZ]; char* tptr; unsigned long tlen; if (nbytes == 0) return 0; if (!db) { /* the Xrm routines expect to be called with the global mutex unlocked. */ XrmDatabase temp_db; int do_destroy; const char *dbname; XrmInitialize(); #ifdef WIN32 dbname = getenv("XERRORDB"); if (!dbname) dbname = ERRORDB; #else dbname = ERRORDB; #endif temp_db = XrmGetFileDatabase(dbname); _XLockMutex(_Xglobal_lock); if (!db) { db = temp_db; do_destroy = 0; } else do_destroy = 1; /* we didn't need to get it after all */ _XUnlockMutex(_Xglobal_lock); if (do_destroy) XrmDestroyDatabase(temp_db); } if (db) { tlen = strlen (name) + strlen (type) + 2; if (tlen <= sizeof(temp)) tptr = temp; else tptr = Xmalloc (tlen); if (tptr) { sprintf(tptr, "%s.%s", name, type); XrmGetResource(db, tptr, "ErrorType.ErrorNumber", &type_str, &result); if (tptr != temp) Xfree (tptr); } else { result.addr = (XPointer) NULL; } } else result.addr = (XPointer)NULL; if (!result.addr) { result.addr = (XPointer) defaultp; result.size = strlen(defaultp) + 1; } (void) strncpy (buffer, (char *) result.addr, nbytes); if (result.size > nbytes) buffer[nbytes-1] = '\0'; return 0; }
rxvt_term::~rxvt_term () { termlist.erase (find (termlist.begin (), termlist.end(), this)); emergency_cleanup (); #if ENABLE_STYLES for (int i = RS_styleCount; --i; ) if (fontset[i] != fontset[0]) delete fontset[i]; #endif delete fontset[0]; #ifdef HAVE_BG_PIXMAP bgPixmap.destroy (); #endif #ifdef HAVE_AFTERIMAGE if (asv) destroy_asvisual (asv, 0); if (asimman) destroy_image_manager (asimman, 0); #endif if (display) { selection_clear (); #ifdef USE_XIM im_destroy (); #endif scrollBar.destroy (); if (gc) XFreeGC (dpy, gc); delete drawable; // destroy all windows if (parent[0]) XDestroyWindow (dpy, parent[0]); for (int i = 0; i < TOTAL_COLORS; i++) if (ISSET_PIXCOLOR (i)) { pix_colors_focused [i].free (this); #if OFF_FOCUS_FADING pix_colors_unfocused [i].free (this); #endif } clear (); display->flush (); /* ideally .put should do this */ displays.put (display); } scr_release (); /* clear all resources */ for (int i = 0; i < allocated.size (); i++) free (allocated [i]); free (selection.text); // TODO: manage env vars in child only(!) free (env_display); free (env_term); free (locale); free (v_buffer); free (incr_buf); delete envv; delete argv; #ifdef KEYSYM_RESOURCE delete keyboard; #endif #ifndef NO_RESOURCES XrmDestroyDatabase (option_db); #endif }
/********************************************************************* * Function: _DtHelpDisplayAreaDestroyCB * * _DtHelpDisplayAreaDestroyCB deallocates all information * associated with it. * *********************************************************************/ void _DtHelpDisplayAreaDestroyCB ( Widget w, XtPointer client_data, XtPointer call_data) { int i; long strIdx; XrmName xrmList[_DtHelpFontQuarkNumber]; Display *dpy; DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) client_data; Boolean usedDef = False; /* * do the gross cleaning */ _DtHelpDisplayAreaClean(client_data); if (NULL != pDAS->canvas) _DtCanvasDestroy (pDAS->canvas); dpy = XtDisplay(pDAS->dispWid); /* * Free the gc's */ XFreeGC (dpy, pDAS->normalGC); XFreeGC (dpy, pDAS->pixmapGC); XFreeGC (dpy, pDAS->invertGC); if (pDAS->def_pix != 0 && XmDestroyPixmap(XDefaultScreenOfDisplay(dpy), pDAS->def_pix) == False) XFreePixmap(dpy, pDAS->def_pix); if (pDAS->context != NULL) { _DtGrDestroyContext(pDAS->context); XtFree((char *) pDAS->context); } /* * destroy the widgets. */ XtDestroyWidget(pDAS->dispWid); if (pDAS->horzScrollWid != NULL) XtDestroyWidget(pDAS->horzScrollWid); if (pDAS->vertScrollWid != NULL) XtDestroyWidget(pDAS->vertScrollWid); /* * free the special characters */ if (pDAS->spc_chars != NULL) free ((char *) pDAS->spc_chars); /* * free the font info. */ _DtHelpGetStringQuarks(xrmList); if (__DtHelpFontIndexGet(pDAS, xrmList, &strIdx) != 0) usedDef = True; if (pDAS->font_info.def_font_db != NULL) XrmDestroyDatabase(pDAS->font_info.def_font_db); if (pDAS->font_info.font_idx_db != NULL) XrmDestroyDatabase(pDAS->font_info.font_idx_db); if (pDAS->font_info.exact_fonts != NULL) { _DtHelpCeFreeStringArray(pDAS->font_info.exact_fonts); free(pDAS->font_info.exact_idx); } if (pDAS->font_info.font_structs != NULL) { /* * if the string index is a positive number, this * indicates that the string font is a font not * a font set and it wouldn't be freed in this * routine. */ for (i = 0; i < pDAS->font_info.struct_cnt; i++) { if (usedDef == True || i != strIdx) XFreeFont(dpy, pDAS->font_info.font_structs[i]); } free(pDAS->font_info.font_structs); } if (pDAS->font_info.font_sets != NULL) { /* * if the string index is a negative number, this turns * it to positive and the tests will succeed. * * if the string index was a font not a fontset, then * this will turn the value negative and the test * will never succeed. */ strIdx = (-strIdx) - 1; for (i = 0; i < pDAS->font_info.set_cnt; i++) { if (usedDef == True || i != strIdx) XFreeFontSet(dpy, pDAS->font_info.font_sets[i]); } free(pDAS->font_info.font_sets); free(pDAS->font_info.fs_metrics); } /* * free the locale dependant information */ if (NULL != pDAS->cant_begin_chars) free (pDAS->cant_begin_chars); if (NULL != pDAS->cant_end_chars) free (pDAS->cant_end_chars); /* * destroy the display area pointer */ XtFree ((char *) pDAS); } /* End DtHelpDisplayAreaDestroy */
ClientDB OpenInputClientDB(char *fileName, char **version, char **dtsessionID) { ClientDBRec *inputDB; char **tmpPtr; char *resourceType; XrmValue resourceValue; *version = (char *)NULL; *dtsessionID = (char *)NULL; _initXrm(); if ((fileName == (char *)NULL) || ((inputDB = (ClientDBRec *)XtMalloc(sizeof(ClientDBRec))) == (ClientDBRec *)NULL)) return (ClientDB)NULL; if ((inputDB->xrmDB = XrmGetFileDatabase(fileName)) == (XrmDatabase)NULL) { XtFree((char *)inputDB); return (ClientDB)NULL; } inputDB->openForInput = True; inputDB->XSMPClients = inputDB->proxyClients = (char **)NULL; inputDB->nXSMPClients = inputDB->nProxyClients = 0; inputDB->nextXSMPClientIndex = inputDB->nextProxyClientIndex = 0; /* Count the number of XSMP and Proxy clients. */ XrmEnumerateDatabase(inputDB->xrmDB, XSMPName, XSMPClass, XrmEnumOneLevel, _countProc, (XPointer)&inputDB->nXSMPClients); XrmEnumerateDatabase(inputDB->xrmDB, proxyName, proxyClass, XrmEnumOneLevel, _countProc, (XPointer)&inputDB->nProxyClients); /* Allocate space for the client IDs and fill from database. */ if (inputDB->nXSMPClients > 0) { if ((inputDB->XSMPClients = (char **)XtMalloc(inputDB->nXSMPClients * sizeof(char *))) == (char **)NULL) { XrmDestroyDatabase(inputDB->xrmDB); XtFree((char *)inputDB); return (ClientDB)NULL; } tmpPtr = inputDB->XSMPClients; XrmEnumerateDatabase(inputDB->xrmDB, XSMPName, XSMPClass, XrmEnumOneLevel, _fillClientIDProc, (XPointer)&tmpPtr); } if (inputDB->nProxyClients > 0) { if ((inputDB->proxyClients = (char **)XtMalloc(inputDB->nProxyClients * sizeof(char *))) == (char **)NULL) { XrmDestroyDatabase(inputDB->xrmDB); XtFree((char *)inputDB->XSMPClients); XtFree((char *)inputDB); return (ClientDB)NULL; } tmpPtr = inputDB->proxyClients; XrmEnumerateDatabase(inputDB->xrmDB, proxyName, proxyClass, XrmEnumOneLevel, _fillClientIDProc, (XPointer)&tmpPtr); } if ((!XrmGetResource(inputDB->xrmDB, versionStr, versionStr, &resourceType, &resourceValue)) || ((*version = XtNewString(resourceValue.addr)) == (char *)NULL) || (!XrmGetResource(inputDB->xrmDB, dtsessionIDStr, dtsessionIDStr, &resourceType, &resourceValue)) || ((*dtsessionID = XtNewString(resourceValue.addr)) == (char *)NULL)) { if (*version) { XtFree(*version); *version = (char *)NULL; } XrmDestroyDatabase(inputDB->xrmDB); XtFree((char *)inputDB->XSMPClients); XtFree((char *)inputDB->proxyClients); XtFree((char *)inputDB); return (ClientDB)NULL; } return (ClientDB)inputDB; }
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; } } } XFree(pfmt); 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, *dpitype; XrmDatabase database; XrmValue geomres, dpires; 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); if (XrmGetResource(database, "Xft.dpi", "String", &dpitype, &dpires) == True) { if (dpires.addr) { displaydpi=atoi(dpires.addr); } } geom = smprint("%s.geometry", label); if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres)) mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height); XrmDestroyDatabase(database); 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; }
/* Function Name: * brGetResourceValueForSetValues * * Description: * Returns the value that should be sent to SetValues. * * Arguments: * res_value - value to set to the resource * size - length of the string returned * * Returns: * value - allocated value. * * Calls: * Xrm- and Xt-stuff */ char *brGetResourceValueForSetValues(char *res_value, unsigned short *size) { static char *temp = NULL; static Cardinal tempSize = 0; static char *ptr = NULL; static Cardinal ptrSize = 0; Arg args[1]; XrmDatabase db = NULL; XrmValue value; char *type; /* * 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. */ if (tempSize < sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2)) { tempSize = (sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2)); if ( (temp = XtRealloc(temp, tempSize)) == NULL ) { fprintf(stderr, "XtRealloc failed!\n"); exit(EXIT_FAILURE); } } sprintf(temp, "%s:%s", RESOURCE_NAME, res_value); XrmPutLineResource(&db, temp); XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &type, &value); if (ptrSize < sizeof(char) * value.size) { ptrSize = sizeof(char) * value.size; if ( (ptr = XtRealloc(ptr, ptrSize)) == NULL ) { fprintf(stderr, "XtRealloc failed!\n"); exit(EXIT_FAILURE); } } memmove (ptr, value.addr, value.size); XrmDestroyDatabase(db); *size = (unsigned short) value.size; return(ptr); } /* brGetResourceValueForSetValues() */
void Parse_options(int *argcp, char **argvp, char *realName, char *host, int *port, int *my_team, int *list, int *join, int *motd, char *nickName, char *dispName, char *shut_msg) { int i, j, firstKeyDef, num; keys_t key; KeySym ks; char *ptr, *str, *myName = "xpilot", *myClass = "XPilot", resValue[MAX_CHARS]; XrmDatabase argDB, rDB; XrmInitialize(); argDB = 0; XrmParseCommand(&argDB, opts, NELEM(opts), myName, argcp, argvp); /* * Check for bad arguments. */ for (i = 1; i < *argcp; i++) { if (argvp[i][0] == '-') { errno = 0; error("Unknown option '%s'", argvp[i]); error("Type: %s -help to see a list of options", argvp[0]); exit(1); } } if (Get_resource(argDB, myName, myClass, "help", NULL, resValue, sizeof resValue) != 0) { Usage(); } if (Get_resource(argDB, myName, myClass, "version", NULL, resValue, sizeof resValue) != 0) { puts(TITLE); exit(0); } Get_resource(argDB, myName, myClass, "shutdown", "", shut_msg, MAX_CHARS); if (Get_string_resource(argDB, myName, myClass, "display", NULL, dispName, MAX_DISP_LEN) == 0 || dispName[0] == '\0') { #ifdef VMS if ((ptr = getenv("DECW$DISPLAY")) != NULL) { #else if ((ptr = getenv("DISPLAY")) != NULL) { #endif strncpy(dispName, ptr, MAX_DISP_LEN); dispName[MAX_DISP_LEN - 1] = '\0'; } else { #ifdef VMS strcpy(dispName, "::0.0"); sprintf(dispName, "%s::0.0", host); #else strcpy(dispName, ":0.0"); #endif } } if ((dpy = XOpenDisplay(dispName)) == NULL) { error("Can't open display '%s'", dispName); exit(1); } Get_resource(argDB, myName, myClass, "visual", "", visualName, sizeof visualName); if (strncasecmp(visualName, "list", 4) == 0) { List_visuals(); exit(0); } Get_file_defaults(&rDB, myName, myClass); XrmMergeDatabases(argDB, &rDB); Get_string_resource(rDB, myName, myClass, "geometry", "", resValue, sizeof resValue); geometry = strdup(resValue); Get_resource(rDB, myName, myClass, "name", realName, nickName, MAX_NAME_LEN); CAP_LETTER(nickName[0]); if (nickName[0] < 'A' || nickName[0] > 'Z') { errno = 0; error("Your player name \"%s\" should start with an uppercase letter", nickName); exit(1); } strncpy(realname, realName, sizeof(realname) - 1); strncpy(name, nickName, sizeof(name) - 1); Get_int_resource(rDB, myName, myClass, "team", TEAM_NOT_SET, my_team); if (*my_team < 0 || *my_team > 9) { *my_team = TEAM_NOT_SET; } team = *my_team; Get_int_resource(rDB, myName, myClass, "port", SERVER_PORT, port); Get_bool_resource(rDB, myName, myClass, "list", "False", list); Get_bool_resource(rDB, myName, myClass, "join", "False", join); Get_bool_resource(rDB, myName, myClass, "motd", "True", motd); Get_float_resource(rDB, myName, myClass, "power", 45.0, &power); Get_float_resource(rDB, myName, myClass, "turnSpeed", 35.0, &turnspeed); Get_float_resource(rDB, myName, myClass, "turnResistance", 0.12, &turnresistance); Get_float_resource(rDB, myName, myClass, "altPower", 35.0, &power_s); Get_float_resource(rDB, myName, myClass, "altTurnSpeed", 25.0, &turnspeed_s); Get_float_resource(rDB, myName, myClass, "altTurnResistance", 0.12, &turnresistance_s); Get_float_resource(rDB, myName, myClass, "sparkProb", 0.50, &spark_prob); spark_rand = (int)(spark_prob * MAX_SPARK_RAND + 0.5f); Get_int_resource(rDB, myName, myClass, "charsPerSecond", 50, &charsPerSecond); Get_bool_resource(rDB, myName, myClass, "markingLights", "True", &i); markingLights = (i == false) ? false : true; Get_int_resource(rDB, myName, myClass, "backgroundPointDist", 8, &map_point_distance); Get_int_resource(rDB, myName, myClass, "backgroundPointSize", DEF_MAP_POINT_SIZE, &map_point_size); LIMIT(map_point_size, MIN_MAP_POINT_SIZE, MAX_MAP_POINT_SIZE); Get_int_resource(rDB, myName, myClass, "sparkSize", DEF_SPARK_SIZE, &spark_size); LIMIT(spark_size, MIN_SPARK_SIZE, MAX_SPARK_SIZE); Get_resource(rDB, myName, myClass, "visual", "", visualName, sizeof visualName); Get_bool_resource(rDB, myName, myClass, "mono", "False", &i); mono = (i != 0) ? true : false; Get_bool_resource(rDB, myName, myClass, "colorSwitch", "True", &i); colorSwitch = (i != 0) ? true : false; Get_int_resource(rDB, myName, myClass, "maxColors", 4, &maxColors); Get_string_resource(rDB, myName, myClass, "black", "", color_names[BLACK], sizeof(color_names[BLACK])); Get_string_resource(rDB, myName, myClass, "white", "", color_names[WHITE], sizeof(color_names[WHITE])); Get_string_resource(rDB, myName, myClass, "blue", "", color_names[BLUE], sizeof(color_names[BLUE])); Get_string_resource(rDB, myName, myClass, "red", "", color_names[RED], sizeof(color_names[RED])); for (i = 0; i < MAX_COLORS; i++) { char buf[8], def[MAX_COLOR_LEN]; sprintf(buf, "color%d", i); strcpy(def, (i < NUM_COLORS) ? color_names[i] : ""); Get_string_resource(rDB, myName, myClass, buf, def, color_names[i], sizeof(color_names[i])); } instruments = 0; Get_bool_resource(rDB, myName, myClass, "showShipName", "True", &i); if (i) { SET_BIT(instruments, SHOW_SHIP_NAME); } Get_bool_resource(rDB, myName, myClass, "showHUD", "True", &i); if (i) { SET_BIT(instruments, SHOW_HUD_INSTRUMENTS); } Get_bool_resource(rDB, myName, myClass, "verticalHUDLine", "False", &i); if (i) { SET_BIT(instruments, SHOW_HUD_VERTICAL); } Get_bool_resource(rDB, myName, myClass, "horizontalHUDLine", "True", &i); if (i) { SET_BIT(instruments, SHOW_HUD_HORIZONTAL); } Get_bool_resource(rDB, myName, myClass, "fuelMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_FUEL_METER); } Get_bool_resource(rDB, myName, myClass, "fuelGauge", "True", &i); if (i) { SET_BIT(instruments, SHOW_FUEL_GAUGE); } Get_bool_resource(rDB, myName, myClass, "turnSpeedMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_TURNSPEED_METER); } Get_bool_resource(rDB, myName, myClass, "powerMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_POWER_METER); } Get_bool_resource(rDB, myName, myClass, "packetSizeMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_SIZE_METER); } Get_bool_resource(rDB, myName, myClass, "packetLossMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_LOSS_METER); } Get_bool_resource(rDB, myName, myClass, "packetDropMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_DROP_METER); } Get_bool_resource(rDB, myName, myClass, "slidingRadar", "False", &i); if (i) { SET_BIT(instruments, SHOW_SLIDING_RADAR); } Get_bool_resource(rDB, myName, myClass, "outlineWorld", "False", &i); if (i) { SET_BIT(instruments, SHOW_OUTLINE_WORLD); } Get_bool_resource(rDB, myName, myClass, "clock", "False", &i); if (i) { SET_BIT(instruments, SHOW_CLOCK); } Get_float_resource(rDB, myName, myClass, "speedFactHUD", 0.0, &hud_move_fact); Get_float_resource(rDB, myName, myClass, "speedFactPTR", 0.0, &ptr_move_fact); Get_int_resource(rDB, myName, myClass, "fuelNotify", 500, &fuelLevel3); Get_int_resource(rDB, myName, myClass, "fuelWarning", 200, &fuelLevel2); Get_int_resource(rDB, myName, myClass, "fuelCritical", 100, &fuelLevel1); Get_resource(rDB, myName, myClass, "gameFont", GAME_FONT, gameFontName, sizeof gameFontName); Get_resource(rDB, myName, myClass, "messageFont", MESSAGE_FONT, messageFontName, sizeof messageFontName); Get_resource(rDB, myName, myClass, "scoreListFont", SCORE_LIST_FONT, scoreListFontName, sizeof scoreListFontName); Get_resource(rDB, myName, myClass, "buttonFont", BUTTON_FONT, buttonFontName, sizeof buttonFontName); Get_resource(rDB, myName, myClass, "textFont", TEXT_FONT, textFontName, sizeof textFontName); Get_resource(rDB, myName, myClass, "talkFont", TALK_FONT, talkFontName, sizeof talkFontName); Get_int_resource(rDB, myName, myClass, "receiveWindowSize", DEF_RECEIVE_WINDOW_SIZE, &receive_window_size); LIMIT(receive_window_size, MIN_RECEIVE_WINDOW_SIZE, MAX_RECEIVE_WINDOW_SIZE); #ifdef SOUND Get_string_resource(rDB, myName, myClass, "sounds", SOUNDFILE, sounds, sizeof sounds); Get_int_resource(rDB, myName, myClass, "maxVolume", 100, &maxVolume); Get_resource(rDB, myName, myClass, "audioServer", NULL, audioServer, sizeof audioServer); #endif Get_bool_resource(rDB, myName, myClass, "toggleShield", "False", &toggle_shield); /* * Key bindings */ maxKeyDefs = 2 * NUM_KEYS; if ((keyDefs = (keydefs_t *) malloc(maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } num = 0; for (i = 0; i < NELEM(keyResources); i++) { key = keyResources[i].key; Get_resource(rDB, myName, myClass, keyResources[i].resource, keyResources[i].fallback, resValue, sizeof resValue); firstKeyDef = num; for (str = strtok(resValue, " \t\r\n"); str != NULL; str = strtok(NULL, " \t\r\n")) { if ((ks = XStringToKeysym(str)) == NoSymbol) { printf("\"%s\" is not a valid keysym.\n", str); continue; } for (j = firstKeyDef; j < num; j++) { if (keyDefs[j].keysym == ks && keyDefs[j].key == key) { break; } } if (j < num) { continue; } if (num >= maxKeyDefs) { maxKeyDefs += NUM_KEYS; if ((keyDefs = (keydefs_t *) realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } } keyDefs[num].keysym = ks; keyDefs[num].key = key; num++; } } if (num < maxKeyDefs) { maxKeyDefs = num; if ((keyDefs = (keydefs_t *) realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } } XrmDestroyDatabase(rDB); #ifdef SOUND audioInit(dispName); #endif /* SOUND */ }
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; }