Exemplo n.º 1
0
void
rxvt_init ()
{
  ptytty::init ();

  if (!ev_default_loop (0))
    rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n");

  rxvt_environ = environ;

  signal (SIGHUP,  SIG_IGN);
  signal (SIGPIPE, SIG_IGN);

  sig_handlers.sw_term.start (SIGTERM); ev_unref ();
  sig_handlers.sw_int.start  (SIGINT);  ev_unref ();

  /* need to trap SIGURG for SVR4 (Unixware) rlogin */
  /* signal (SIGURG, SIG_DFL); */

  old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
  // TODO: handle this with exceptions and tolerate the memory loss
  XSetIOErrorHandler (rxvt_xioerror_handler);

  XrmInitialize ();
}
Exemplo n.º 2
0
void XtToolkitInitialize()
{
    static Boolean initialized = False;

    LOCK_PROCESS;
    if (initialized) {
	UNLOCK_PROCESS;
	return;
    }
    initialized = True;
    UNLOCK_PROCESS;
    /* Resource management initialization */
    XrmInitialize();
    _XtResourceListInitialize();

    /* Other intrinsic intialization */
    _XtConvertInitialize();
    _XtEventInitialize();
    _XtTranslateInitialize();

    /* Some apps rely on old (broken) XtAppPeekEvent behavior */
    if(getenv("XTAPPPEEKEVENT_SKIPTIMER"))
	XtAppPeekEvent_SkipTimer = True;
    else 
	XtAppPeekEvent_SkipTimer = False;
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
GC setup(Display * dpy, int argc, char ** argv, int *width_r, int *height_r,
		XFontSet *font_r){
	int width, height;
	unsigned long background, border;
	Window win;
	GC pen;
	XGCValues values;

	XFontSet font;
	XrmDatabase db;

	XrmInitialize();
	db = XrmGetDatabase(dpy);
	XrmParseCommand(&db, xrmTable, sizeof(xrmTable)/sizeof(xrmTable[0]),
		"xtut7", &argc, argv);

	font = getFont(dpy, db, "xtut7.font", "xtut7.Font", "fixed");
	background = getColour(dpy,  db, "xtut7.background", "xtut7.BackGround", "DarkGreen");
	border = getColour(dpy,  db, "xtut7.border", "xtut7.Border", "LightGreen");
	values.foreground = getColour(dpy,  db, "xtut7.foreground", "xtut7.ForeGround", "Red");


	width = 400;
	height = 400;

	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), /* display, parent */
		0,0, /* x, y: the window manager will place the window elsewhere */
		width, height, /* width, height */
		2, border, /* border width & colour, unless you have a window manager */
		background); /* background colour */

	Xutf8SetWMProperties(dpy, win, "XTut7", "xtut7", argv, argc,
		NULL, NULL, NULL);

	/* create the pen to draw lines with */
	values.line_width = 1;
	values.line_style = LineSolid;
	/*values.font = font->fid; */
	pen = XCreateGC(dpy, win, GCForeground|GCLineWidth|GCLineStyle,&values);

	/* tell the display server what kind of events we would like to see */
	XSelectInput(dpy, win, ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ExposureMask);

	/* okay, put the window on the screen, please */
	XMapWindow(dpy, win);

	*width_r = width; *height_r = height;
	*font_r = font;

	return pen;
}
Exemplo n.º 6
0
Arquivo: SmDB.c Projeto: juddy/edcde
static void
_initXrm(void)
{
    if (!xrmInitialized)
    {
	XrmInitialize(); /* Just in case. */

	anyQuark = XrmStringToQuark("?");
	XSMPName[0] = proxyName[0] = anyQuark;
	XSMPClass[0] = XrmStringToClass("Client");
	proxyClass[0] = XrmStringToClass("ProxyClient");
	XSMPName[1] = XSMPClass[1] =
	    proxyName[1] = proxyClass[1] = NULLQUARK;
	xrmInitialized = True;
    }
}
Exemplo n.º 7
0
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;
	}
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
/* This needs to be updated to reflect the new world. */
static void
DO_Initialize() {

extern void QuarkInitialize();
extern void ResourceListInitialize();
extern void EventInitialize();
extern void TranslateInitialize();
extern void CursorsInitialize();

    /* Resource management initialization */
    QuarkInitialize();
    XrmInitialize();
    ResourceListInitialize();

    /* Other intrinsic intialization */
    EventInitialize();
    TranslateInitialize();
    CursorsInitialize();
    InitializeCallbackTable();


}
Exemplo n.º 12
0
XrmDatabase
_XInitKeysymDB()
{
#if 1
    if (!initialized)
    {
	char *dbname;

	XrmInitialize();
	/* use and name of this env var is not part of the standard */
	/* implementation-dependent feature */
	dbname = getenv("XKEYSYMDB");
	if (!dbname)
	    dbname = KEYSYMDB;
	keysymdb = XrmGetFileDatabase(dbname);
	if (keysymdb)
	    Qkeysym[0] = XrmStringToQuark("Keysym");
	initialized = True;
    }
#endif
    return keysymdb;
}
Exemplo n.º 13
0
/* 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);
	}
}
Exemplo n.º 14
0
static Bool
init_x11( char * error_buf )
{
	/*XXX*/ /* Namely, support for -display host:0.0 etc. */
	XrmQuark common_quarks_list[20];  /*XXX change number of elements if necessary */
	XrmQuarkList ql = common_quarks_list;
	XGCValues gcv;
	char *common_quarks =
		"String."
		"Blinkinvisibletime.blinkinvisibletime."
		"Blinkvisibletime.blinkvisibletime."
		"Clicktimeframe.clicktimeframe."
		"Doubleclicktimeframe.doubleclicktimeframe."
		"Wheeldown.wheeldown."
		"Wheelup.wheelup."
		"Submenudelay.submenudelay."
		"Scrollfirst.scrollfirst."
		"Scrollnext.scrollnext";

	char * atom_names[AI_count] = {
		"RESOLUTION_X",
		"RESOLUTION_Y",
		"PIXEL_SIZE",
		"SPACING",
		"RELATIVE_WEIGHT",
		"FOUNDRY",
		"AVERAGE_WIDTH",
		"CHARSET_REGISTRY",
		"CHARSET_ENCODING",
		"CREATE_EVENT",
		"WM_DELETE_WINDOW",
		"WM_PROTOCOLS",
		"WM_TAKE_FOCUS",
		"_NET_WM_STATE",
		"_NET_WM_STATE_SKIP_TASKBAR",
		"_NET_WM_STATE_MAXIMIZED_VERT",
		"_NET_WM_STATE_MAXIMIZED_HORZ",
		"_NET_WM_NAME",
		"_NET_WM_ICON_NAME",
		"UTF8_STRING",
		"TARGETS",
		"INCR",
		"PIXEL",
		"FOREGROUND",
		"BACKGROUND",
		"_MOTIF_WM_HINTS",
		"_NET_WM_STATE_MODAL",
		"_NET_SUPPORTED",
		"_NET_WM_STATE_MAXIMIZED_HORIZ",
		"text/plain;charset=UTF-8",
		"_NET_WM_STATE_STAYS_ON_TOP",
		"_NET_CURRENT_DESKTOP",
		"_NET_WORKAREA",
		"_NET_WM_STATE_ABOVE"
	};
	char hostname_buf[256], *hostname = hostname_buf;

	guts. click_time_frame = 200;
	guts. double_click_time_frame = 200;
	guts. visible_timeout = 500;
	guts. invisible_timeout = 500;
	guts. insert = true;
	guts. last_time = CurrentTime;

	guts. ri_head = guts. ri_tail = 0;
	DISP = XOpenDisplay( do_display);
	
	if (!DISP) {
		char * disp = getenv("DISPLAY");
		snprintf( error_buf, 256, "Error: Can't open display '%s'", 
					do_display ? do_display : (disp ? disp : ""));
		free( do_display);
		do_display = nil;
		return false;
	}
	free( do_display);
	do_display = nil;
	XSetErrorHandler( x_error_handler);
	guts.main_error_handler = x_error_handler;
	(void)x_io_error_handler;
	XCHECKPOINT;
	guts.connection = ConnectionNumber( DISP);

	{
		struct sockaddr name;
		unsigned int l = sizeof( name);
		guts. local_connection = getsockname( guts.connection, &name, &l) >= 0 && l == 0;
	}
	
#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
	if ( XShapeQueryExtension( DISP, &guts.shape_event, &guts.shape_error)) {
		guts. shape_extension = true;
	} else {
		guts. shape_extension = false;
	}
#else
	guts. shape_extension = false;
#endif
#ifdef USE_MITSHM
	if ( !do_no_shmem && XShmQueryExtension( DISP)) {
		guts. shared_image_extension = true;
		guts. shared_image_completion_event = XShmGetEventBase( DISP) + ShmCompletion;
	} else {
		guts. shared_image_extension = false;
		guts. shared_image_completion_event = -1;
	}
#else
	guts. shared_image_extension = false;
	guts. shared_image_completion_event = -1;
#endif
	guts. randr_extension = false;
#ifdef HAVE_X11_EXTENSIONS_XRANDR_H
	{
		int dummy;
		if ( XRRQueryExtension( DISP, &dummy, &dummy))
			guts. randr_extension = true;
	}	 
#endif
#ifdef HAVE_X11_EXTENSIONS_XRENDER_H
	{
		int dummy;
		if ( XRenderQueryExtension( DISP, &dummy, &dummy))
			guts. render_extension = true;
	}	 
#endif
#ifdef HAVE_X11_EXTENSIONS_XCOMPOSITE_H
	{
		int dummy;
		if (XQueryExtension(DISP, COMPOSITE_NAME, &guts.composite_opcode, &dummy, &dummy))
			guts. composite_extension = true;
	}	 
#endif
	XrmInitialize();
	guts.db = get_database();
	XrmStringToQuarkList( common_quarks, common_quarks_list);
	guts.qString = *ql++;
	guts.qBlinkinvisibletime = *ql++;
	guts.qblinkinvisibletime = *ql++;
	guts.qBlinkvisibletime = *ql++;
	guts.qblinkvisibletime = *ql++;
	guts.qClicktimeframe = *ql++;
	guts.qclicktimeframe = *ql++;
	guts.qDoubleclicktimeframe = *ql++;
	guts.qdoubleclicktimeframe = *ql++;
	guts.qWheeldown = *ql++;
	guts.qwheeldown = *ql++;
	guts.qWheelup = *ql++;
	guts.qwheelup = *ql++;
	guts.qSubmenudelay = *ql++;
	guts.qsubmenudelay = *ql++;
	guts.qScrollfirst = *ql++;
	guts.qscrollfirst = *ql++;
	guts.qScrollnext = *ql++;
	guts.qscrollnext = *ql++;

	guts. mouse_buttons = XGetPointerMapping( DISP, guts. buttons_map, 256);
	XCHECKPOINT;

	guts. limits. request_length = XMaxRequestSize( DISP);
	guts. limits. XDrawLines = guts. limits. request_length - 3;
	guts. limits. XFillPolygon = guts. limits. request_length - 4;
	guts. limits. XDrawSegments = (guts. limits. request_length - 3) / 2;
	guts. limits. XDrawRectangles = (guts. limits. request_length - 3) / 2;
	guts. limits. XFillRectangles = (guts. limits. request_length - 3) / 2;
	guts. limits. XFillArcs =
		guts. limits. XDrawArcs = (guts. limits. request_length - 3) / 3;
	XCHECKPOINT;
	SCREEN = DefaultScreen( DISP);

	/* XXX - return code? */
	guts. root = RootWindow( DISP, SCREEN);
	guts. displaySize. x = DisplayWidth( DISP, SCREEN);
	guts. displaySize. y = DisplayHeight( DISP, SCREEN);
	XQueryBestCursor( DISP, guts. root,
							guts. displaySize. x,     /* :-) */
							guts. displaySize. y,
							&guts. cursor_width,
							&guts. cursor_height);
	XCHECKPOINT;
	
	TAILQ_INIT( &guts.paintq);
	TAILQ_INIT( &guts.peventq);
	TAILQ_INIT( &guts.bitmap_gc_pool);
	TAILQ_INIT( &guts.screen_gc_pool);
	TAILQ_INIT( &guts.argb_gc_pool);

	guts. currentFocusTime = CurrentTime;
	guts. windows = hash_create();
	guts. menu_windows = hash_create();
	guts. ximages = hash_create();
	gcv. graphics_exposures = false;
	guts. menugc = XCreateGC( DISP, guts. root, GCGraphicsExposures, &gcv);
	guts. resolution. x = 25.4 * guts. displaySize. x / DisplayWidthMM( DISP, SCREEN) + .5;
	guts. resolution. y = 25.4 * DisplayHeight( DISP, SCREEN) / DisplayHeightMM( DISP, SCREEN) + .5;
	guts. depth = DefaultDepth( DISP, SCREEN);
	guts. idepth = get_idepth();
	if ( guts.depth == 1) guts. qdepth = 1; else
	if ( guts.depth <= 4) guts. qdepth = 4; else
	if ( guts.depth <= 8) guts. qdepth = 8; else
		guts. qdepth = 24;
	guts. byte_order = ImageByteOrder( DISP);
	guts. bit_order = BitmapBitOrder( DISP);
	if ( BYTEORDER == LSB32 || BYTEORDER == LSB64)
		guts. machine_byte_order = LSBFirst;
	else if ( BYTEORDER == MSB32 || BYTEORDER == MSB64)
		guts. machine_byte_order = MSBFirst;
	else {
		sprintf( error_buf, "UAA_001: weird machine byte order: %08x", BYTEORDER);
		return false;
	}  

	XInternAtoms( DISP, atom_names, AI_count, 0, guts. atoms);

	guts. null_pointer = nilHandle;
	guts. pointer_invisible_count = 0;
	guts. files = plist_create( 16, 16);
	prima_rebuild_watchers();
	guts. wm_event_timeout = 100;
	guts. menu_timeout = 200;
	guts. scroll_first = 200;
	guts. scroll_next = 50;
	apc_timer_create( CURSOR_TIMER);
	apc_timer_set_timeout(CURSOR_TIMER, 2);
	apc_timer_create( MENU_TIMER);
	apc_timer_set_timeout( MENU_TIMER,  guts. menu_timeout);
	apc_timer_create( MENU_UNFOCUS_TIMER);
	apc_timer_set_timeout( MENU_UNFOCUS_TIMER, 50);
	if ( !prima_init_clipboard_subsystem( error_buf)) return false;
	if ( !prima_init_color_subsystem( error_buf)) return false;
	if ( !prima_init_font_subsystem( error_buf)) return false;
#ifdef WITH_GTK2
	if (!prima_gtk_init()) return false;
#endif
	bzero( &guts. cursor_gcv, sizeof( guts. cursor_gcv));
	guts. cursor_gcv. cap_style = CapButt;
	guts. cursor_gcv. function = GXcopy;

	gethostname( hostname, 256);
	hostname[255] = '\0';
	XStringListToTextProperty((char **)&hostname, 1, &guts. hostname);
	
	guts. net_wm_maximization = prima_wm_net_state_read_maximization( guts. root, NET_SUPPORTED);

	if ( do_sync) XSynchronize( DISP, true);
	return true;
}
Exemplo n.º 15
0
/* 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++;
	}
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
static void bubblemon_session_defaults(void)
{
    /* handy way to collect all this stuff in one place */
    typedef struct {
	char *name;		/* name as appears in Xdefaults */
	int type;		/* int, double, or color, see up */
	void *var;		/* pointer to value - only handles INT atm */
    } xrm_vars;

    /* XResource stuff */
    char name[BUFSIZ] = "", *ptr;
    XrmDatabase db = NULL;
    XrmValue val;
    char *type;
    int i;

    xrm_vars tab[] = {
	{"bubblemon.maxbubbles", INT_VAL, &bm.maxbubbles},
	{"bubblemon.air_noswap", COLOR_VAL, &bm.air_noswap},
	{"bubblemon.air_maxswap", COLOR_VAL, &bm.air_maxswap},
	{"bubblemon.liquid_noswap", COLOR_VAL, &bm.liquid_noswap},
	{"bubblemon.liquid_maxswap", COLOR_VAL, &bm.liquid_maxswap},
	{"bubblemon.ripples", DOUBLE_VAL, &bm.ripples},
	{"bubblemon.gravity", DOUBLE_VAL, &bm.gravity},
	{"bubblemon.volatility", DOUBLE_VAL, &bm.volatility},
	{"bubblemon.viscosity", DOUBLE_VAL, &bm.viscosity},
	{"bubblemon.speed_limit", DOUBLE_VAL, &bm.speed_limit}
    };

    /* number of CPU load samples */
    bm.samples = 16;

    /* default colors.  changeable from Xdefaults */
    bm.air_noswap = 0x2299ff;
    bm.liquid_noswap = 0x0055ff;
    bm.air_maxswap = 0xff0000;
    bm.liquid_maxswap = 0xaa0000;

    /* default bubble engine parameters.  Changeable from Xdefaults */
    bm.maxbubbles = 100;
    bm.ripples = 0.2;
    bm.gravity = 0.01;
    bm.volatility = 1.0;
    bm.viscosity = 0.98;
    bm.speed_limit = 1.0;

    db = NULL;
    XrmInitialize();

    /* get users's local Xdefaults */
    if ((ptr = getenv("HOME")) != NULL) {
	snprintf(name, sizeof(name), "%s/.Xdefaults", ptr);
    }

    /* get the database and parse resources if we have some */
    if ((db = XrmGetFileDatabase(name)) != NULL) {
	for (i = 0; i < (sizeof(tab) / sizeof(tab[0])); i++) {
	    if (XrmGetResource(db, tab[i].name, tab[i].name, &type, &val)) {
		if (val.size > 0)	/* no empty strings and shit like that */
		    switch (tab[i].type) {
		    case INT_VAL:
			*(int *) tab[i].var = atoi(val.addr);
			break;
		    case DOUBLE_VAL:
			*(double *) tab[i].var = atof(val.addr);
			break;
		    case COLOR_VAL:
			sscanf(val.addr, "#%x", (int *) tab[i].var);
			break;
		    default:
			/* WTF? */
			break;
		    }
	    }
	}
    }
#define RANGE_CHECK(x, min, max, def) \
    if ((x) > (max) || (x) < (min)) { \
	fprintf(stderr, #x" value is out of range. Using default value ("#def")\n"); \
	(x) = (def); \
    }

    /* range validation. 3l33t hackerz NO PASARAN */
    RANGE_CHECK(bm.air_noswap, 0, 0xffffff, 0x2299ff);
    RANGE_CHECK(bm.liquid_noswap, 0, 0xffffff, 0x0055ff);
    RANGE_CHECK(bm.air_maxswap, 0, 0xffffff, 0xff0000);
    RANGE_CHECK(bm.liquid_maxswap, 0, 0xffffff, 0xaa0000);

    RANGE_CHECK(bm.maxbubbles, 10, 200, 100);
    RANGE_CHECK(bm.ripples, 0, 1, 0.2);
    RANGE_CHECK(bm.gravity, 0.005, 0.5, 0.01);
    RANGE_CHECK(bm.volatility, 0.1, 2, 1.0);
    RANGE_CHECK(bm.viscosity, 0, 1.0, 0.98);
    RANGE_CHECK(bm.speed_limit, 0.5, 2, 1.0);

#undef RANGE_CHECK

    /* convert doubles into integer representation */
    bm.ripples_int = MAKE_INTEGER(bm.ripples);
    bm.gravity_int = MAKE_INTEGER(bm.gravity);
    bm.volatility_int = MAKE_INTEGER(bm.volatility);
    bm.viscosity_int = MAKE_INTEGER(bm.viscosity);
    bm.speed_limit_int = MAKE_INTEGER(bm.speed_limit);
}
Exemplo n.º 18
0
char* MpXResource (const char *Application, const char *Name, const char *Class)
{
    const int STRLEN = 256;
    static int init = true;
    static XrmDatabase DefaultResource;
    char CompName[STRLEN], CompClass[STRLEN], *type;
    XrmValue result;

    // initialize X resource manager
    if (init) {
        init = false;
        XrmInitialize();
        DefaultResource = (XrmDatabase) 0;
        char tmp[STRLEN];
        XrmDatabase EnvironmentResource;

        // search file $HOME/.Xresources
        char *homedir = getenv("HOME");
        if (!homedir) homedir = ".";
        sprintf(tmp,"%s/.Xresources", homedir);
        DefaultResource = XrmGetFileDatabase(tmp);

#ifdef DEBUG
        cerr << "seaching HOME='" << tmp << "' "
             << (DefaultResource ? "was successful" : "failed") 
             << endl;
#endif
        
        // merge file given by $XENVIRONMENT
        char *xenviron = (char *) getenv("XENVIRONMENT");
        if (xenviron) {
            EnvironmentResource = XrmGetFileDatabase(xenviron);
          
#ifdef DEBUG
            cerr << "seaching XENVIRONMENT='" << xenviron << "' "
                 << (EnvironmentResource ? "was successful" : "failed") 
                 << endl;
#endif

            // merge both databases
            if (EnvironmentResource) {
                if (!DefaultResource) 
                    DefaultResource = EnvironmentResource;
                else 
                    XrmMergeDatabases(EnvironmentResource, &DefaultResource);
            }
        }
        
    }
    
    // no resource database available
    if (!DefaultResource) return 0;
    
    // now search resource in database
    strcpy (CompName, Application);
    strcat (CompName, ".");
    strcat (CompName, Name);
  
    strcpy (CompClass, "Program");
    strcat (CompClass, ".");
    strcat (CompClass, Class);

    XrmGetResource(DefaultResource, CompName, CompClass, &type, &result); 
    return result.addr;
}
Exemplo n.º 19
0
int _glfwPlatformInit(void)
{
#if !defined(X_HAVE_UTF8_STRING)
    // HACK: If the current locale is "C" and the Xlib UTF-8 functions are
    //       unavailable, apply the environment's locale in the hope that it's
    //       both available and not "C"
    //       This is done because the "C" locale breaks wide character input,
    //       which is what we fall back on when UTF-8 support is missing
    if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0)
        setlocale(LC_CTYPE, "");
#endif

    XInitThreads();
    XrmInitialize();

    _glfw.x11.display = XOpenDisplay(NULL);
    if (!_glfw.x11.display)
    {
        const char* display = getenv("DISPLAY");
        if (display)
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Failed to open display %s", display);
        }
        else
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: The DISPLAY environment variable is missing");
        }

        return GLFW_FALSE;
    }

    _glfw.x11.screen = DefaultScreen(_glfw.x11.display);
    _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen);
    _glfw.x11.context = XUniqueContext();

    getSystemContentScale(&_glfw.x11.contentScaleX, &_glfw.x11.contentScaleY);

    if (!initExtensions())
        return GLFW_FALSE;

    _glfw.x11.helperWindowHandle = createHelperWindow();
    _glfw.x11.hiddenCursorHandle = createHiddenCursor();

    if (XSupportsLocale())
    {
        XSetLocaleModifiers("");

        _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL);
        if (_glfw.x11.im)
        {
            if (!hasUsableInputMethodStyle())
            {
                XCloseIM(_glfw.x11.im);
                _glfw.x11.im = NULL;
            }
        }
    }

#if defined(__linux__)
    if (!_glfwInitJoysticksLinux())
        return GLFW_FALSE;
#endif

    _glfwInitTimerPOSIX();

    _glfwPollMonitorsX11();
    return GLFW_TRUE;
}
Exemplo n.º 20
0
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 */
}
Exemplo n.º 21
0
void conf_init(void) {
    init_default_values();
    gboolean keyoption = FALSE;

    Display *dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
    XrmInitialize();
    char basename[12] = "/.Xdefaults";
    char *filename = strcat(getpwuid(getuid())->pw_dir, basename);
    XrmSetDatabase(dpy, XrmGetFileDatabase(filename));

    char *op;
    int i;
    Option o;
    for (i = 0; i < OPTION_COUNT; i++) {
        o = options[i];
        if ((op = XGetDefault(dpy, "stjerm", o.long_name)))
            read_value(o.long_name, op);
    }
    char color[8];
    for (i = 0; i < 16; i++) {
        sprintf(color, "color%d", i);
        if ((op = XGetDefault(dpy, "stjerm", color)))
            read_value(color, op);
    }

    for (i = 1; i < sargc; i++) {
        if (sargv != NULL) {
            if (!strcmp(sargv[i], "--help")) {
                print_help();
                exit(1);
            } else if (!strcmp(sargv[i], "--info")) {
                print_info();
                exit(1);
            } else if (!strcmp("--toggle", sargv[i])) {
                kill(get_stjerm_pid(), SIGUSR1);
                exit(1);
            } else if (!strcmp("--version", sargv[i]) || !strcmp("-v", sargv[i])){
	     	    print_version();
		        exit(1);
	        }
        }
        if (i + 1>= sargc)
            break;

        read_value(sargv[i], sargv[i + 1]);
    }

    if (keyoption == FALSE && _key == 0) {
        printf("Hint: You started stjerm without specifying a shortcut key\n"
               "      To show/hide stjerm run stjerm with the toggle option\n"
               "      like this: stjerm --toggle");
    }

    struct stat st;
    if (stat(_shell, &st) != 0) {
        fprintf(stderr, "ERROR: The shell '%s' can't be opened\n", _shell);
        exit(1);
    }

    if (_lines < 0) {
        fprintf(stderr, "ERROR: A scrollback line count < 0 is not allowed\n");
        exit(1);
    }

    if (keyoption == TRUE && _key == 0) {
        fprintf(stderr, "ERROR: Wrong shortcut key is defined\n");
        exit(1);
    }

    if (read_colors > 0 && read_colors < 16) {
        fprintf(stderr, "ERROR: Read only %d colors, not 16\n"
                "Specify a complete color palette\n", read_colors);
        exit(1);
    }

    signal(SIGUSR1, (__sighandler_t) mainwindow_toggle);

    int scrw = gdk_screen_get_width(gdk_screen_get_default());
    int scrh = gdk_screen_get_height(gdk_screen_get_default());

    if (_pos == POS_TOP) {
        _posx = (scrw - _width) / 2;
        _posy = 0;
    } else if (_pos == POS_BOTTOM) {
        _posx = (scrw - _width) / 2;
        _posy = scrh - _height;
    } else if (_pos == POS_LEFT) {
        _posx = 0;
        _posy = (scrh - _height) / 2;
    } else if (_pos == POS_RIGHT) {
        _posx = scrw - _width;
        _posy = (scrh - _height) / 2;
    } else if (_pos == POS_TOPLEFT) {
        _posx = 0;
        _posy = 0;
    } else if (_pos == POS_TOPRIGHT) {
        _posx = scrw - _width;
        _posy = 0;
    } else if (_pos == POS_BOTTOMLEFT) {
        _posx = 0;
        _posy = scrh - _height;
    } else if (_pos == POS_BOTTOMRIGHT) {
        _posx = scrw - _width;
        _posy = scrh - _height;
    }
}
Exemplo n.º 22
0
Arquivo: ax.c Projeto: radekp/spectemu
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);

} 
Exemplo n.º 23
0
Arquivo: main.c Projeto: Arkq/alock
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;
}
Exemplo n.º 24
0
static void setup(void) {
    XrmInitialize();
}