コード例 #1
0
ファイル: resources.C プロジェクト: aidanfarrow/GC_tidy
// Return a database of default settings
XrmDatabase app_defaults(Display *display)
{
    static XrmDatabase db = NULL;
    if (db != NULL)
	return db;

    // Add builtin fallback defaults.
    int i = 0;
    while (ddd_fallback_resources[i] != 0)
	XrmPutLineResource(&db, ddd_fallback_resources[i++]);

    // Add app-defaults file, overriding fallback defaults.
    static String app_name  = 0;
    static String app_class = 0;

    if (app_name == 0)
	XtGetApplicationNameAndClass(display, &app_name, &app_class);

    String app_defaults_file = 
	XtResolvePathname(display, NULL, app_class, NULL, NULL, NULL, 0, NULL);
    if (app_defaults_file != NULL)
    {
	XrmDatabase db2 = XrmGetFileDatabase(app_defaults_file);
	if (db2 != 0)
	    XrmMergeDatabases(db2, &db);
    }

    return db;
}
コード例 #2
0
int
main (int argc, char **argv)
{
  int event_number, error_number;
  int major, minor;
  int nscreens = 0;
  XineramaScreenInfo *xsi;
  int i;

  XtAppContext app;
  Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
					   &argc, argv, 0, 0, 0);
  Display *dpy = XtDisplay (toplevel_shell);
  XtGetApplicationNameAndClass (dpy, &progname, &progclass);

  if (!XineramaQueryExtension(dpy, &event_number, &error_number))
    {
      fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> False\n",
	      blurb());
      fprintf(stderr, "%s: server does not support the Xinerama extension.\n",
	      blurb());
      exit(1);
    }
  else
    fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> %d, %d\n",
            blurb(), event_number, error_number);

  if (!XineramaIsActive(dpy))
    {
      fprintf(stderr, "%s: XineramaIsActive(dpy) ==> False\n", blurb());
      fprintf(stderr, "%s: server says Xinerama is turned off.\n", blurb());
      exit(1);
    }
  else
    fprintf(stderr, "%s: XineramaIsActive(dpy) ==> True\n", blurb());

  if (!XineramaQueryVersion(dpy, &major, &minor))
    {
      fprintf(stderr, "%s: XineramaQueryVersion(dpy, ...) ==> False\n",
              blurb());
      fprintf(stderr, "%s: server didn't report Xinerama version numbers?\n",
	      blurb());
    }
  else
    fprintf(stderr, "%s: XineramaQueryVersion(dpy, ...) ==> %d, %d\n", blurb(),
	    major, minor);

  xsi = XineramaQueryScreens (dpy, &nscreens);
  fprintf(stderr, "%s: %d Xinerama screens\n", blurb(), nscreens);
  
  for (i = 0; i < nscreens; i++)
    fprintf (stderr, "%s:   screen %d: %dx%d+%d+%d\n",
             blurb(),
             xsi[i].screen_number,
             xsi[i].width, xsi[i].height,
             xsi[i].x_org, xsi[i].y_org);
  XFree (xsi);
  XSync (dpy, False);
  exit (0);
}
コード例 #3
0
ファイル: appres.c プロジェクト: Bluerise/bitrig-xenocara
int
main (int argc, char *argv[])
{
    Widget toplevel;
    char *iname = NONAME, *cname = NONAME;
    XtAppContext xtcontext;
    XrmName names[101];
    XrmClass classes[101];
    int i;
    int mode = XrmEnumAllLevels;

    ProgramName = argv[0];
    if (argc > 1 && argv[1][0] != '-') {
	cname = argv[1];
	if (argc > 2 && argv[2][0] != '-')
	    iname = argv[2];
    }

    XrmStringToClassList(cname, classes);
    XrmStringToNameList(iname, names);
    for (i = 0; names[i]; i++)
	;
    if (!i || classes[i] || !classes[i-1]) usage ();
    argv[0] = XrmNameToString(names[0]);

    toplevel = XtAppInitialize(&xtcontext, XrmClassToString(classes[0]),
			       NULL, 0, &argc, argv, NULL, NULL, 0);

    iname = NULL;
    cname = NULL;
    for (i = 1; i < argc; i++) {
	if (!strcmp(argv[i], "-1"))
	    mode = XrmEnumOneLevel;
	else if (!strcmp(argv[i], "-V")) {
	    printf("%s\n", PACKAGE_STRING);
	    exit(0);
	}
	else if (argv[i][0] == '-')
	    usage();
	else if (!cname)
	    cname = argv[i];
	else if (!iname)
	    iname = argv[i];
	else
	    usage();
    }

    if (!iname) {
	XtGetApplicationNameAndClass(XtDisplay(toplevel), &iname, &cname);
	names[0] = XrmStringToName(iname);
    }

    XrmQString = XrmPermStringToQuark("String");

    XrmEnumerateDatabase(XtDatabase(XtDisplay(toplevel)),
			 names, classes, mode,
			 DumpEntry, (XPointer)stdout);

    return (0);
}
コード例 #4
0
ファイル: PrintS.c プロジェクト: unix-junkie/motif
XtEnum XmPrintToFile(Display *pdpy, 
		     char *file_name,
		     XPFinishProc finish_proc, 
		     XPointer client_data)
{
    FileCallbackRec *callback;
    int pid;
    XPContext pcontext ;
    String application_name, application_class, display_name;
    FILE *file;
    int filedes[2];
    
    /* make sure we can open the file for writing */
    if ((file = fopen(file_name, "w")) == NULL) {
      return False;
    }

    if ((pipe(filedes)) == -1) {
      return False;
    }

    /* its important to flush before we fork, to make sure that the
       XpStartJob gets through first in the parent */
    XFlush(pdpy);

    XtGetApplicationNameAndClass(pdpy,
				 &application_name, &application_class);

    display_name = XDisplayString(pdpy) ;
    pcontext = XpGetContext(pdpy) ;
    pid = fork();

    if (pid == 0) {
      ChildPrintToFile(display_name, pcontext, file, file_name, filedes[1],
		       application_name, application_class);
    }
    else if (pid < 0) {
      return False;
    }

    /* we are in the parent */

    fclose(file);
    close(filedes[1]);

    /* allocate the space for a callback */
    callback = (FileCallbackRec *) XtMalloc(sizeof(FileCallbackRec));
    callback->display = pdpy;
    callback->pipe = filedes[0];
    callback->finish_proc = finish_proc;
    callback->client_data = client_data;

    /* notification that the child has completed */
    callback->input_id = 
        XtAppAddInput(XtDisplayToApplicationContext(pdpy), 
		      callback->pipe, (XtPointer)XtInputReadMask,
		      FilePipeCB, callback);

    return True;
}
コード例 #5
0
ファイル: Host.c プロジェクト: idunham/dtextra
static Boolean
set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
{
    Boolean ReConnect = False;

    /*
       printf("set_values()\n");
     */
    if (Host_Terminator(new_w) == NULL)
    {
	Host_Terminator(new_w) = XtNewString("\r\n");
    }
    if (Host_Name(new_w) == NULL)
    {
	Host_Name(new_w) = XtNewString("localhost");
    }
    if (Host_Port(new_w) == NULL)
    {
	String Name;
	String Class;

	XtGetApplicationNameAndClass(XtDisplay(XtParent(new_w)), &Name, &Class);
	Host_Port(new_w) = XtNewString(Name);
    }
    if (strcmp(Host_Name(old), Host_Name(new_w)) != 0)
    {
	ReConnect = True;
    }
    if (strcmp(Host_Port(old), Host_Port(new_w)) != 0)
    {
	ReConnect = True;
    }
    if (Host_Type(old) != Host_Type(new_w))
    {
	ReConnect = True;
    }
    if (Host_Terminator(new_w) != Host_Terminator(old))
    {
    	XtFree(Host_Terminator(old));
    }
    if (Host_Name(new_w) != Host_Name(old))
    {
    	XtFree(Host_Name(old));
    }
    if (Host_Port(new_w) != Host_Port(old))
    {
    	XtFree(Host_Port(old));
    }
    if (ReConnect)
    {
	Disconnect(new_w);
	Connect(new_w);
    }
    return (False);
}
コード例 #6
0
ファイル: tips.C プロジェクト: fooeybartoni/CSI702
static string app_value(const string& resource, const string& value)
{
    String app_name;
    String app_class;
    XtGetApplicationNameAndClass(XtDisplay(find_shell()), 
				 &app_name, &app_class);

    if (resource.contains(string(app_name) + ".", 0))
	return string(app_class) + resource.from(".") + ": " + value;
    else
	return string(app_class) + "*" + resource + ": " + value;
}
コード例 #7
0
ファイル: kxsconfig.cpp プロジェクト: Fat-Zer/kdeartwork
int main(int argc, char *argv[])
{
  KCmdLineArgs::init(argc, argv, appName, I18N_NOOP("KXSConfig"), description, version);

  KCmdLineArgs::addCmdLineOptions(options);

  KApplication app;

  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
  if(args->count()==0)
    exit(1);

  /* We must read exactly the same resources as xscreensaver.
     That means we must have both the same progclass *and* progname,
     at least as far as the resource database is concerned.  So,
     put "xscreensaver" in argv[0] while initializing Xt.
   */
  const char *dummyargs[] = { "xscreensaver" };
  int dummyargc = 1;
  progname = dummyargs[0];

  // Teach Xt to use the Display that TQt has already opened.
  XtToolkitInitialize ();
  XtAppContext xtApp = XtCreateApplicationContext ();
  Display *dpy = qt_xdisplay();
  XtAppSetFallbackResources (xtApp, const_cast<char**>(defaults));
  XtDisplayInitialize (xtApp, dpy, progname, progclass, 0, 0,
                       &dummyargc,
                       const_cast<char**>(dummyargs));
  Widget toplevel_shell = XtAppCreateShell (progname, progclass,
	  applicationShellWidgetClass,
	  dpy, 0, 0);
  dpy = XtDisplay (toplevel_shell);
  db = XtDatabase (dpy);
  XtGetApplicationNameAndClass (dpy, const_cast<char**>(&progname),
                                const_cast<char**>(&progclass));

  TQString name = TQString::fromLocal8Bit(args->arg(args->count() - 1));
  KXSConfigDialog *dialog=new KXSConfigDialog(args->arg(0), name);
  if ( dialog->create() ) {
      dialog->show();
      app.setMainWidget(dialog);
      app.exec();
  } else {
      KMessageBox::sorry(0,
	      i18n("No configuration available for %1").tqarg(name),
	      name );
  }

  delete dialog;
}
コード例 #8
0
ファイル: PrintS.c プロジェクト: unix-junkie/motif
Widget
XmPrintSetup(
             Widget           video_widget,
             Screen           *print_screen,
             String            print_shell_name,
             ArgList           args,
             Cardinal          num_args)
{
    String video_name, video_class ;
    Widget pappshell ;
    Widget print_shell;
    Display  *print_display = DisplayOfScreen(print_screen);

    /* get to the video app root shell */
    while(!XtIsApplicationShell(video_widget))
	video_widget = XtParent(video_widget);

    if (!video_widget) return NULL;

    XtGetApplicationNameAndClass(XtDisplay(video_widget),
                                 &video_name, &video_class);

    /* we want to be able to specify things like:
       dtpad.print*textFontList: somefont
       dtpad.print*background:white
       so we create a first shell unrealized and them a popup
       named "print".
       */
    pappshell = XtVaAppCreateShell(video_name, video_class,
                                   applicationShellWidgetClass, 
                                   print_display, 
                                   XmNscreen, print_screen, 
                                   NULL);

    /* then create the XmPrintShell */
    print_shell = XtCreatePopupShell(print_shell_name, 
				     xmPrintShellWidgetClass, 
				     pappshell, args, num_args);

    /* Add callback to destroy application Shell parent. */
    XtAddCallback(print_shell, XmNdestroyCallback, 
                  _XmDestroyParentCallback, (XtPointer) NULL) ;

    /* we're mapping/unmapping at start/end page time */
    XtSetMappedWhenManaged(print_shell, False);

    /* realize the shell now, so that XmPrintPopupPDM works dy default */
    XtRealizeWidget(print_shell);

    return print_shell ;
}
コード例 #9
0
void KXtWidget::init(const char* name, WidgetClass widget_class,
                    Widget parent, QWidget* qparent,
                    ArgList args, Cardinal num_args,
                    bool managed)
{
    need_reroot=FALSE;
    xtparent = 0;
    if (parent ) {
        Q_ASSERT(!qparent);
        xtw = XtCreateWidget(name, widget_class, parent, args, num_args);
        if ( widget_class == qWidgetClass )
            ((QWidgetRec*)xtw)->qwidget.qxtwidget = this;
        xtparent = parent;
        if (managed)
            XtManageChild(xtw);
    } else {
        Q_ASSERT(!managed);

        String n, c;
        XtGetApplicationNameAndClass(qt_xdisplay(), &n, &c);
        xtw = XtAppCreateShell(n, c, widget_class, qt_xdisplay(),
                               args, num_args);
        if ( widget_class == qWidgetClass )
            ((QWidgetRec*)xtw)->qwidget.qxtwidget = this;
    }

    if ( qparent ) {
        XtResizeWidget( xtw, 100, 100, 0 );
        XtSetMappedWhenManaged(xtw, False);
        XtRealizeWidget(xtw);
        XSync(qt_xdisplay(), False);    // I want all windows to be created now
        XReparentWindow(qt_xdisplay(), XtWindow(xtw), qparent->winId(), x(), y());
        XtSetMappedWhenManaged(xtw, True);
        need_reroot=TRUE;
    }

    Arg reqargs[20];
    Cardinal nargs=0;
    XtSetArg(reqargs[nargs], XtNx, x());        nargs++;
    XtSetArg(reqargs[nargs], XtNy, y());        nargs++;
    XtSetArg(reqargs[nargs], XtNwidth, width());        nargs++;
    XtSetArg(reqargs[nargs], XtNheight, height());      nargs++;
    //XtSetArg(reqargs[nargs], "mappedWhenManaged", False);     nargs++;
    XtSetValues(xtw, reqargs, nargs);

    //#### destroy();   MLK

    if (!parent || XtIsRealized(parent))
        XtRealizeWidget(xtw);
}
コード例 #10
0
ファイル: Display.c プロジェクト: att/uwin
/*
 * This is the real place, where we try to find the XmDisplay widget of
 * a display. If we can't get our hands on the widget, we create one.
 *
 * NOTICE:
 * We now support for user-defined XmDisplay subclasses. Such user-defined
 * replacements can be activated by calling _XmSetXmDisplayClass with a
 * pointer to an appropiate class record.
 */
static Widget 
GetXmDisplay(Display *Dsp)
{
    Widget DisplayWidget = NULL;
    Arg Args[5];
    Cardinal ArgCount;
    String AppName, AppClass;

    /*
     * If we haven't yet a XmDisplay widget for that particular display,
     * we're creating it on the fly.
     */
    if ((PerDisplayWidgetContext == PDWC_None) ||
	(XFindContext(Dsp, PDWC_RID_DisplayWidget, PerDisplayWidgetContext,
		      (XPointer *)&DisplayWidget) != XCSUCCESS))
    {
	/*
	 * Because we need to realize that display widget in the next step,
	 * we have to set the widget's initial size -- otherwise we will
	 * crash with that nasty error message saying, that the shell has
	 * zero with/height...
	 */
	ArgCount = 0;

	XtSetArg(Args[ArgCount], XmNwidth, 1); ArgCount++;
	XtSetArg(Args[ArgCount], XmNheight, 1); ArgCount++;
	XtSetArg(Args[ArgCount], XmNmappedWhenManaged, False); ArgCount++;

	XtGetApplicationNameAndClass(Dsp, &AppName, &AppClass);

	DisplayWidget = XtAppCreateShell(AppName, AppClass, __XmDisplayClass,
					 Dsp, Args, ArgCount);
	/*
	 * The XmDisplay widget is now already registered as the display
	 * object (this is done in DisplayInitialize()).
	 */
    }

    /*
     * Make sure we have a window.
     */
    if (!XtIsRealized(DisplayWidget))
    {
	XtRealizeWidget(DisplayWidget);
    }

    return DisplayWidget;
}
コード例 #11
0
ファイル: file_menu.c プロジェクト: ma-tech/MAPaint
void set_topl_title(
  String	name)
{
  String	class_return;
  char		str_buff[64], app_name[32], *tmpStr;
  int		i, basename_start;

  if( globals.app_name == NULL ){
    /* get the top level dialog and application name */
    XtGetApplicationNameAndClass(XtDisplay(globals.topl),
				 &globals.app_name, &class_return);
  }

  /* check for emage flag 
     remove any trailing "_EMAGE" */
  strncpy(app_name, globals.app_name, 30);
  if((tmpStr = strstr(app_name, "_EMAGE"))){
    app_name[tmpStr - app_name] = '\0';
  }
  if( globals.emageFlg == True ){
    sprintf(app_name, "%s(EMAGE)", globals.app_name);
  }
  else {
    sprintf(app_name, "%s", globals.app_name);
  }
  
  /* use given name or globals.file or NULL */
  if( name == NULL ){
    name = globals.file;
  }
  if( name ){
    /* get file basename */
    for(i=0, basename_start=0; i < strlen(name); i++){
      if( name[i] == '/' ){
	basename_start = i+1;
      }
    }
    sprintf(str_buff, "%s: %s", app_name, name+basename_start);
  }
  else {
    sprintf(str_buff, "%s", app_name);
  }

  XtVaSetValues(globals.topl, XtNtitle, str_buff, NULL);

  return;
}
コード例 #12
0
ファイル: Host.c プロジェクト: idunham/dtextra
static void
initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args)
{
    String Name;
    String Class;

    /*
       printf("initialize() - %i args\n", *num_args);
       printf("Fd   %i\n", Host_Fd(new_w));
       printf("Name %s\n", Host_Name(new_w));
       printf("Port %s\n", Host_Port(new_w));
     */
    Host_Mode(new_w) = MODE_ASCII;
    Host_Throttle(new_w) = False;
    Host_InputId(new_w) = 0;
    Host_OutputId(new_w) = 0;
    Host_Fd(new_w) = -1;
    Host_OutputMaxSize(new_w) = 1;
    Host_OutputSize(new_w) = 0;
    Host_OutputData(new_w) = XtMalloc(Host_OutputMaxSize(new_w));
    Host_InputMaxSize(new_w) = 1;
    Host_InputSize(new_w) = 0;
    Host_InputData(new_w) = XtMalloc(Host_InputMaxSize(new_w));
    Host_Dialog(new_w) = NULL;
    Host_InputNeed(new_w) = 0;
    Host_BinaryTimeOutId(new_w) = (XtIntervalId)NULL;
    Host_NumClients(new_w) = 0;
    Host_ClientList(new_w) = NULL;
    Host_SaveDialog(new_w) = NULL;
    if (Host_Terminator(new_w) == NULL)
    {
	Host_Terminator(new_w) = XtNewString("\r\n");
    }
    if (Host_Name(new_w) == NULL)
    {
	Host_Name(new_w) = XtNewString("localhost");
    }
    if (Host_Port(new_w) == NULL)
    {
	XtGetApplicationNameAndClass(XtDisplay(XtParent(new_w)), &Name, &Class);
	Host_Port(new_w) = XtNewString(Name);
    }
    Connect(new_w);
}
コード例 #13
0
ファイル: prefFile.c プロジェクト: adrian-bl/nedit
/*
** SavePreferences
**
** Create or replace an application preference file according to
** the resource descriptions in rsrcDesrcip.
*/
int SavePreferences(Display *display, const char *fullName,
        const char *fileHeader,	PrefDescripRec *rsrcDescrip, int nRsrc)
{
    char *appName, *appClass, **enumStrings;
    FILE *fp;
    int type;
    int i;
    
    /* open the file */
    if ((fp = fopen(fullName, "w")) == NULL)
    	return False;
    
    /* write the file header text out to the file */
    fprintf(fp, "%s\n", fileHeader);
    
    /* write out the resources so they can be read by XrmGetFileDatabase */
    XtGetApplicationNameAndClass(display, &appName, &appClass);
    for (i=0; i<nRsrc; i++) {
    	if (rsrcDescrip[i].save) {
    	    type = rsrcDescrip[i].dataType;
    	    fprintf(fp, "%s.%s: ", appName, rsrcDescrip[i].name);
    	    if (type == PREF_STRING)
    		fprintf(fp, "%s", (char *)rsrcDescrip[i].valueAddr);
    	    if (type == PREF_ALLOC_STRING)
    		fprintf(fp, "%s", *(char **)rsrcDescrip[i].valueAddr);
    	    else if (type == PREF_ENUM) {
    		enumStrings = (char **)rsrcDescrip[i].arg;
    		fprintf(fp,"%s", enumStrings[*(int *)rsrcDescrip[i].valueAddr]);
    	    } else if (type == PREF_INT)
    		fprintf(fp, "%d", *(int *)rsrcDescrip[i].valueAddr);
    	    else if (type == PREF_BOOLEAN) {
    		if (*(int *)rsrcDescrip[i].valueAddr)
    	    	    fprintf(fp, "True");
    		else
    	    	    fprintf(fp, "False");
    	    }
    	    fprintf(fp, "\n");
    	}
    }
    fclose(fp);
    return True;
}
コード例 #14
0
ファイル: test-passwd.c プロジェクト: Ro6afF/XScreenSaver
int
main (int argc, char **argv)
{
  enum { PASS, SPLASH, TTY } which;
  Widget toplevel_shell = 0;
  saver_screen_info ssip;
  saver_info sip;
  saver_info *si = &sip;
  saver_preferences *p = &si->prefs;
  struct passwd *pw;

  memset(&sip, 0, sizeof(sip));
  memset(&ssip, 0, sizeof(ssip));

  si->nscreens = 1;
  si->screens = si->default_screen = &ssip;
  ssip.global = si;

  global_si_kludge = si;
  real_stderr = stderr;
  real_stdout = stdout;

  si->version = (char *) malloc (5);
  memcpy (si->version, screensaver_id + 17, 4);
  si->version[4] = 0;
  progname = argv[0];
  {
    char *s = strrchr(progname, '/');
    if (*s) strcpy (progname, s+1);
  }

  if (argc != 2) goto USAGE;
  else if (!strcmp (argv[1], "pass"))   which = PASS;
  else if (!strcmp (argv[1], "splash")) which = SPLASH;
  else if (!strcmp (argv[1], "tty"))    which = TTY;
  else
    {
    USAGE:
      fprintf (stderr, "usage: %s [ pass | splash | tty ]\n", progname);
      exit (1);
    }

#ifdef NO_LOCKING
  if (which == PASS || which == TTY)
    {
      fprintf (stderr, "%s: compiled with NO_LOCKING\n", progname);
      exit (1);
    }
#endif

#ifndef NO_LOCKING
  /* before hack_uid() for proper permissions */
  lock_priv_init (argc, argv, True);

  hack_uid (si);

  if (! lock_init (argc, argv, True))
    {
      si->locking_disabled_p = True;
      si->nolock_reason = "error getting password";
    }
#endif

  progclass = "XScreenSaver";

  if (!setlocale (LC_CTYPE, ""))
    fprintf (stderr, "%s: warning: could not set default locale\n",
             progname);


  if (which != TTY)
    {
      toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0,
                                        &argc, argv, fallback,
                                        0, 0);

      si->dpy = XtDisplay (toplevel_shell);
      p->db = XtDatabase (si->dpy);
      si->default_screen->toplevel_shell = toplevel_shell;
      si->default_screen->screen = XtScreen(toplevel_shell);
      si->default_screen->default_visual =
        si->default_screen->current_visual =
        DefaultVisualOfScreen(si->default_screen->screen);
      si->default_screen->screensaver_window =
        RootWindowOfScreen(si->default_screen->screen);
      si->default_screen->current_depth =
        visual_depth(si->default_screen->screen,
                     si->default_screen->current_visual);

      ssip.width = WidthOfScreen(ssip.screen);
      ssip.height = HeightOfScreen(ssip.screen);

      db = p->db;
      XtGetApplicationNameAndClass (si->dpy, &progname, &progclass);

      load_init_file (si->dpy, &si->prefs);
    }

  p->verbose_p = True;

  pw = getpwuid (getuid ());
  si->user = strdup (pw->pw_name);

/*  si->nscreens = 0;
  si->screens = si->default_screen = 0; */

  while (1)
    {
#ifndef NO_LOCKING
      if (which == PASS)
        {
	  si->unlock_cb = gui_auth_conv;
          si->auth_finished_cb = auth_finished_cb;

          debug_passwd_window_p = True;
	  xss_authenticate(si, True);

          if (si->unlock_state == ul_success)
            fprintf (stderr, "%s: authentication succeeded\n", progname);
          else
            fprintf (stderr, "%s: authentication FAILED!\n", progname);

          XSync(si->dpy, False);
          fprintf (stderr, "\n######################################\n\n");
          sleep (3);
        }
      else
#endif
      if (which == SPLASH)
        {
          XEvent event;
          make_splash_dialog (si);
          XtAppAddTimeOut (si->app, p->splash_duration + 1000,
                           idle_timer, (XtPointer) si);
          while (si->splash_dialog)
            {
              XtAppNextEvent (si->app, &event);
              if (event.xany.window == si->splash_dialog)
                handle_splash_event (si, &event);
              XtDispatchEvent (&event);
            }
          XSync (si->dpy, False);
          sleep (1);
        }
#ifndef NO_LOCKING
      else if (which == TTY)
        {
          si->unlock_cb = text_auth_conv;

          printf ("%s: Authenticating user %s\n", progname, si->user);
          xss_authenticate(si, True);

          if (si->unlock_state == ul_success)
            printf ("%s: Ok!\n", progname);
          else
            printf ("%s: Wrong!\n", progname);
        }
#endif
      else
        abort();
    }

  free(si->user);
}
コード例 #15
0
int main(int argc, char **argv)
{
   AppInfo app;
   XEvent event;

   memset(&app, 0, sizeof(app));
   
   progclass = "SshAskpass";
   app.toplevelShell = XtAppInitialize(&(app.appContext), progclass,
					NULL, 0, &argc, argv,
					defaults, NULL, 0);
   app.argc = argc;
   app.argv = argv;
   app.dpy = XtDisplay(app.toplevelShell);
   app.screen = DefaultScreenOfDisplay(app.dpy);
   app.rootWindow = RootWindowOfScreen(app.screen);
   app.black = BlackPixel(app.dpy, DefaultScreen(app.dpy));
   app.white = WhitePixel(app.dpy, DefaultScreen(app.dpy));
   app.colormap = DefaultColormapOfScreen(app.screen);
   app.resourceDb = XtDatabase(app.dpy);
   XtGetApplicationNameAndClass(app.dpy, &progname, &progclass);
   app.appName = progname;
   app.appClass = progclass;
   /* For resources.c. */
   db = app.resourceDb;
   
   /* Seconds after which keyboard/pointer grab fail. */
   app.grabFailTimeout = 5;
   /* Number of seconds to wait between grab attempts. */
   app.grabRetryInterval = 1;
   
   app.pid = getpid();

   {
      struct rlimit resourceLimit;
      int status;
      
      status = getrlimit(RLIMIT_CORE, &resourceLimit);
      if (-1 == status) {
	 fprintf(stderr, "%s[%ld]: getrlimit failed (%s)\n", app.appName,
		 (long) app.pid, strerror(errno));
	 exit(EXIT_STATUS_ERROR);
      }
      resourceLimit.rlim_cur = 0;
      status = setrlimit(RLIMIT_CORE, &resourceLimit);
      if (-1 == status) {
	 fprintf(stderr, "%s[%ld]: setrlimit failed (%s)\n", app.appName,
		 (long) app.pid, strerror(errno));
	 exit(EXIT_STATUS_ERROR);
      }
   }
   
   app.xResolution =
      WidthOfScreen(app.screen) * 1000 / WidthMMOfScreen(app.screen);
   app.yResolution =
      HeightOfScreen(app.screen) * 1000 / HeightMMOfScreen(app.screen);
   
   createDialog(&app);
   createGCs(&app);
   
   app.eventMask = 0;
   app.eventMask |= ExposureMask;
   app.eventMask |= ButtonPressMask;
   app.eventMask |= ButtonReleaseMask;
   app.eventMask |= Button1MotionMask;
   app.eventMask |= KeyPressMask;

   createDialogWindow(&app);
   
   XMapWindow(app.dpy, app.dialog->dialogWindow);
   if (app.inputTimeout > 0) {
      app.inputTimeoutActive = True;
      app.inputTimeoutTimerId =
	 XtAppAddTimeOut(app.appContext, app.inputTimeout,
			 handleInputTimeout, (XtPointer) &app);
   }

   
   while(True) {
      XtAppNextEvent(app.appContext, &event);
      switch (event.type) {
       case Expose:
	 grabServer(&app);
	 grabKeyboard(&app);
	 grabPointer(&app);
	 if (event.xexpose.count) {
	    break;
	 }
	 paintDialog(&app);
	 break;
       case ButtonPress:
       case ButtonRelease:
	 handleButtonPress(&app, &event);
	 break;
       case MotionNotify:
	 handlePointerMotion(&app, &event);
       case KeyPress:
	 handleKeyPress(&app, &event);
	 break;
       case ClientMessage:
	 if ((32 == event.xclient.format) &&
	     ((unsigned long) event.xclient.data.l[0] ==
	      app.wmDeleteWindowAtom)) {
	    cancelAction(&app);
	 }
	 break;
       default:
	 break;
      }
   }

   fprintf(stderr, "%s[%ld]: This should not happen.\n", app.appName,
	   (long) app.pid);
   return(EXIT_STATUS_ANOMALY);
}
コード例 #16
0
// Fetch the X library directory, using xmkmf(1)
static const _XtString xlibdir(Display *display, bool verbose = false)
{
    static bool tried = false;
    static const _XtString dir = 0;

    if (tried)
	return dir;
    tried = true;

    if (!is_cmd_file(cmd_file("xmkmf")))
	return dir;		// No `xmkmf' in PATH
    if (!is_cmd_file(cmd_file("make")))
	return dir;		// No `make' in PATH

    static const char *shell_command =
	""
#include "xlibdir.C"
	"";

    String me, my_class;
    XtGetApplicationNameAndClass(display, &me, &my_class);

    if (verbose)
    {
	std::cout << "Checking for X11 library directory... ";
	std::cout.flush();
    }

    const string s1 = "/bin/sh -c " + sh_quote(shell_command); 
    FILE *fp = popen(s1.chars(), "r");
    if (fp == 0)
    {
	if (verbose)
	{
	    std::cout << strerror(errno) << "\n";
	    std::cout.flush();
	}
	return dir;
    }

    char buffer[PATH_MAX];
    buffer[0] = '\0';
    fgets(buffer, sizeof(buffer), fp);
    pclose(fp);

    int len = strlen(buffer);
    if (len > 0 && buffer[len - 1] == '\n')
	buffer[len - 1] = '\0';

    if (buffer[0] == '/')	// Sanity check
	dir = (String)XtNewString(buffer);

    if (verbose)
    {
	if (dir)
	    std::cout << dir << "\n";
	else
	    std::cout << "(not found)\n";
	std::cout.flush();
    }

    return dir;
}
コード例 #17
0
/*
 * ------------------------------------------------------------------------
 * Name: PdmShellCreate
 *
 * Description:
 *
 *     This function creates a top level application shell.
 *
 * Return value:
 *
 *     0 if successful; a PDM_EXIT code if not.
 *
 */
static int
PdmShellCreate(PdmShell* me,
	       const String* fallback_resources,
	       int* argc_in_out, String* argv_in_out)
{
    String app_class;
    String app_name;
    XmPixelSet pixelSets[XmCO_NUM_COLORS];
    XrmClass class_list[3];
    XrmDatabase db;
    XrmName name_list[3];
    XrmRepresentation rep_type;
    XrmValue value;
    int decor;
    int funcs;
    short secondary_id;
    /*
     * create the application context and open the video display
     */
    XtToolkitInitialize();
    XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL,
		      (XtPointer)NULL);
    me->app_context = XtCreateApplicationContext();

    XtAppSetFallbackResources(me->app_context, (String*)fallback_resources);

    me->display =
	XtOpenDisplay(me->app_context, (String)NULL,
		      (String)NULL, "Dtpdm",
		      PdmOptions, XtNumber(PdmOptions),
		      argc_in_out, argv_in_out);
    if((Display*)NULL == me->display)
	return PDM_EXIT_VXAUTH;
    XtGetApplicationNameAndClass(me->display, &app_name, &app_class);
    /*
     * the fallback resources are only intended for the video display, so
     * remove them from the application context
     */
    XtAppSetFallbackResources(me->app_context, (String*)NULL);
    /*
     * get the parent video window id from the display's resource database
     */
    db = XtDatabase(me->display);
    name_list[0] = XrmStringToQuark(app_name);
    name_list[1] = XrmStringToQuark("parentWindowStr");
    name_list[2] = NULLQUARK;
    class_list[0] = XrmStringToQuark(app_class);
    class_list[1] = XrmStringToQuark("ParentWindowStr");
    class_list[2] = NULLQUARK;
    XrmQGetResource(db, name_list, class_list, &rep_type, &value);
    if(!value.addr) return PDM_EXIT_ERROR;
    me->parent_window = (Window)strtoul((char*)value.addr, (char**)NULL, 0);
    /*
     * obtain the parent video window's attributes
     */
    if(!XGetWindowAttributes(me->display, me->parent_window, &me->parent_attr))
	return PDM_EXIT_ERROR;
    /*
     * register interest in the DestroyNotify event for the parent window
     */
    XSelectInput(me->display, me->parent_window, StructureNotifyMask);
    /*
     * create the application shell
     */
    decor = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MINIMIZE
	| MWM_DECOR_MAXIMIZE;
    funcs = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE
	| MWM_FUNC_MAXIMIZE;
    me->widget = 
	XtVaAppCreateShell(app_name, app_class,
			   applicationShellWidgetClass,
			   me->display,
			   XmNdeleteResponse, XmDESTROY,
			   XmNmappedWhenManaged, False,
			   XmNmwmDecorations, decor,
			   XmNmwmFunctions, funcs,
			   XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL,
			   XmNscreen, me->parent_attr.screen,
			   XmNtransient, True,
			   NULL);
    /*
     * pick up the secondary color set, so that the PDM presents the same
     * colors as a secondary window. (the XmColorObj is created by the
     * the XmDisplay object, which is created when the app shell is
     * created)
     */
    if(XmeGetColorObjData(XtScreen(me->widget), (int*)NULL,
			  pixelSets, XmCO_NUM_COLORS,
			  (short*)NULL, (short*)NULL, (short*)NULL,
			  &secondary_id, (short*)NULL))
    {
	/*
	 * In the Xrm database, reassign primary color resource values
	 * with the corresponding secondary color values. This will cause
	 * subsequently created widgets that utilize colors from the
	 * primary set to actually present secondary colors.
	 */
	db = XtScreenDatabase(XtScreen(me->widget));
	value.size = sizeof(Pixel);
	value.addr = (char*)&pixelSets[secondary_id].bg;
	XrmPutResource (&db, "*background", "Pixel", &value);
	XrmPutResource (&db, "*frameBackground", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].fg;
	XrmPutResource (&db, "*foreground", "Pixel", &value);
	XrmPutResource (&db, "*backPageForeground", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].bs;
	XrmPutResource (&db, "*bottomShadowColor", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].ts;
	XrmPutResource (&db, "*topShadowColor", "Pixel", &value);
    }
    /*
     * get the application resources
     */
    XtGetApplicationResources(me->widget, me,
			      PdmResources, XtNumber(PdmResources),
			      NULL, 0);
    /*
     * return
     */
    return 0;
}
コード例 #18
0
ファイル: Host.c プロジェクト: idunham/dtextra
static Boolean
Connect(Widget W)
{
    if (Host_Name(W) && strlen(Host_Name(W)) > 0 &&
        Host_Port(W) && strlen(Host_Port(W)) > 0)
    {
	if (!XtIsRealized(XtParent(W)))
	{
	    XtAddEventHandler(XtParent(W),
			      StructureNotifyMask,
			      False,
			      (XtEventHandler)DelayedConnect,
			      W);
	}
	else
	{
	    while (XtAppPending(XtWidgetToApplicationContext(XtParent(W))))
	    {
		XtAppProcessEvent(XtWidgetToApplicationContext(XtParent(W)), XtIMAll);
	    }
	    switch (Host_Type(W))
	    {
	    case XltHOST_CLIENT:
		if (strcmp(Host_Name(W), "-") == 0)
		{
		    Host_Fd(W) = fileno(stdin);
		}
		else
		{
		    Host_Fd(W) = SockOpen(Host_Name(W), Host_Port(W));
		}
		if (Host_Fd(W) >= 0)
		{
		    _XltHostCallbackStruct tmp;
		    String Name;
		    String Class;
		    FILE *xrdb;
		    String xrdb_command;
		    String base = "xrdb -merge -nocpp -display";

		    Host_InputId(W) = XtAppAddInput(XtWidgetToApplicationContext(W),
						    Host_Fd(W),
						    (XtPointer)XtInputReadMask,
						    (XtInputCallbackProc)InputHandler,
						    W);
		    xrdb_command = XtMalloc(strlen(base) + strlen(DisplayString(XtDisplay(XtParent(W)))) + 2);
		    sprintf(xrdb_command, "%s %s", base, DisplayString(XtDisplay(XtParent(W))));
		    xrdb = popen(xrdb_command, "w");
		    if (xrdb != NULL)
		    {
			XtGetApplicationNameAndClass(XtDisplay(XtParent(W)), &Name, &Class);
			fprintf(xrdb, "%s.Host: %s\n%s.Service: %s\n",
				Class,
				Host_Name(W),
				Class,
				Host_Port(W));
			pclose(xrdb);
		    }
		    XtFree(xrdb_command);
		    Host_Throttle(W) = False;
		    tmp.reason = XltCR_CONNECT;
		    XtCallCallbackList(W, Host_ConnectCallback(W), &tmp);
		}
		break;
	    case XltHOST_SERVER:
		Host_Fd(W) = Listen(Host_Port(W));
		if (Host_Fd(W) > 0)
		{
		    Host_InputId(W) = XtAppAddInput(XtWidgetToApplicationContext(W),
						    Host_Fd(W),
						    (XtPointer)XtInputReadMask,
						    (XtInputCallbackProc)ConnectionRequest,
						    W);
		}
		break;
	    default:
		fprintf(stderr, "%s: Unknown host type\n", XtName(W));
		break;
	    }
	}
    }
    else
    {
    }
    return (True);
}
コード例 #19
0
ファイル: xsublim.c プロジェクト: BuBuaBu/bang-screensaver
int main(int argc,char* argv[])
{
	XtAppContext app;
	int               sig_Number;
	int               sig_Signal[] =
	{
		SIGHUP,
		SIGINT,
		SIGQUIT,
		SIGILL,
		SIGTRAP,
#if defined(SIGIOT)
		SIGIOT,
#endif
		SIGABRT,
#if defined(SIGEMT)
		SIGEMT,
#endif
		SIGFPE,
		SIGBUS,
		SIGSEGV,
#if defined(SIGSYS)
		SIGSYS,
#endif
		SIGTERM,
#if defined(SIGXCPU)
		SIGXCPU,
#endif
#if defined(SIGXFSZ)
		SIGXFSZ,
#endif
#if defined(SIGDANGER)
		SIGDANGER,
#endif
		-1
	};
	Widget            app_App;
	Display*          dpy;
	Window            win_Root;
	XWindowAttributes attr_Win;
	XGCValues         gc_ValFore;
	XGCValues         gc_ValBack;
	GC                gc_GcFore;
	GC                gc_GcBack;
	XFontStruct*      font_Font;
	char*             font_List[] =
	{
		"-*-character-*-r-*-*-*-600-*-*-p-*-*-*",
		"-*-helvetica-*-r-*-*-*-600-*-*-p-*-*-*",
		"-*-lucida-*-r-*-*-*-600-*-*-p-*-*-*",
		"-*-*-*-r-*-sans-*-600-*-*-p-*-*-*",
		"-*-*-*-r-*-*-*-600-*-*-m-*-*-*",
		"-*-helvetica-*-r-*-*-*-240-*-*-p-*-*-*",
		"-*-lucida-*-r-*-*-*-240-*-*-p-*-*-*",
		"-*-*-*-r-*-sans-*-240-*-*-p-*-*-*",
		"-*-*-*-r-*-*-*-240-*-*-m-*-*-*",
		"fixed",
		NULL
	};
	int               font_Index;
	int               text_Length;
	int               text_X;
	int               text_Y;
	int               text_Width;
	int               text_Height;
	char*             text_List[XSUBLIM_TEXT_COUNT];
	int               text_Used[XSUBLIM_TEXT_COUNT];
	char              text_Text[XSUBLIM_TEXT_LENGTH+1];
	char*             text_Phrase;
	char*             text_Word;
	int               text_Index;
	int               text_Item;
	int               text_Count;
	struct
	{
		int outline_X;
		int outline_Y;
	}                 text_Outline[] =
	{
		{ -1,-1 },
		{  1,-1 },
		{ -1, 1 },
		{  1, 1 },
		{  0, 0 }
	};
	int               text_OutlineIndex;
	XImage*           image_Image = NULL;
	int               image_X = 0;
	int               image_Y = 0;
	int               image_Width = 0;
	int               image_Height = 0;
	int               arg_Count;
	int               arg_FlagCenter;
	int               arg_FlagOutline;
	int               arg_FlagScreensaver;
	int               arg_FlagRandom;
	int               arg_DelayShow;
	int               arg_DelayWord;
	int               arg_DelayPhraseMin;
	int               arg_DelayPhraseMax;
	char*             arg_Text;
	char*             arg_Source;

	/* Set-up ---------------------------------------------------------- */

	/* Catch signals */
	Xsublim_Sig_Last = -1;
	for (sig_Number = 0;sig_Signal[sig_Number] != -1;sig_Number++)
	{
		signal(sig_Number,xsublim_Sig_Catch);
	}

	/* Randomize -- only need to do this here because this program
           doesn't use the `screenhack.h' or `lockmore.h' APIs. */
# undef ya_rand_init
        ya_rand_init (0);

	/* Handle all the X nonsense */
#if defined(__sgi)
	SgiUseSchemes("none");
#endif
	for (arg_Count = 0;options[arg_Count].option != NULL;arg_Count++)
	{
		;
	}
	app_App = XtAppInitialize(&app,progclass,options,arg_Count,&argc,argv,
	 defaults,0,0);

        /* jwz */
        if (argc > 1)
          {
            int x = 18;
            int end = 78;
            int i;
            int count = (sizeof(options)/sizeof(*options))-1;
            fprintf(stderr, "Unrecognised option: %s\n", argv[1]);
            fprintf (stderr, "Options include: ");
            for (i = 0; i < count; i++)
              {
                char *sw = options [i].option;
                Bool argp = (options [i].argKind == XrmoptionSepArg);
                int size = strlen (sw) + (argp ? 6 : 0) + 2;
                if (x + size >= end)
                  {
                    fprintf (stderr, "\n\t\t ");
                    x = 18;
                  }
                x += size;
                fprintf (stderr, "%s", sw);
                if (argp) fprintf (stderr, " <arg>");
                if (i != count-1) fprintf (stderr, ", ");
              }
            fprintf (stderr, ".\n");
            exit (-1);
          }

	dpy = XtDisplay(app_App);
	XtGetApplicationNameAndClass(dpy,&progname,&progclass);
	win_Root = RootWindowOfScreen(XtScreen(app_App));
	XtDestroyWidget(app_App);

	/* Get the arguments */
	arg_FlagCenter = get_boolean_resource(dpy, XSUBLIM_ARG_CENTER,"Boolean");
	arg_FlagOutline = get_boolean_resource(dpy, XSUBLIM_ARG_OUTLINE,"Boolean");
	arg_FlagScreensaver = get_boolean_resource(dpy, XSUBLIM_ARG_SCREENSAVER,
	 "Boolean");
	arg_FlagRandom = get_boolean_resource(dpy, XSUBLIM_ARG_RANDOM,"Boolean");
	arg_DelayShow = get_integer_resource(dpy, XSUBLIM_ARG_DELAYSHOW,"Integer");
	arg_DelayWord = get_integer_resource(dpy, XSUBLIM_ARG_DELAYWORD,"Integer");
	arg_DelayPhraseMin = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMIN,
	 "Integer");
	arg_DelayPhraseMax = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMAX,
	 "Integer");
	if (arg_DelayPhraseMax < arg_DelayPhraseMin)
	{
		arg_DelayPhraseMax = arg_DelayPhraseMin;
	}

	/* Get the phrases */
	text_Index = 0;
	text_Item = 0;
	text_Count = 0;
	memset(text_Used,0,sizeof(text_Used));
	arg_Source = get_string_resource(dpy, XSUBLIM_ARG_FILE,"Filename");
	if (arg_Source != NULL)
	{
		FILE*       file_Fs;
		struct stat file_Stat;

		file_Fs = fopen(arg_Source,"rb");
		if (file_Fs == NULL)
		{
			fprintf(stderr,"%s: Could not open '%s'\n",progname,
			 arg_Source);
			exit(-1);
		}
		if (fstat(fileno(file_Fs),&file_Stat) != 0)
		{
			fprintf(stderr,"%s: Could not stat '%s'\n",progname,
			 arg_Source);
			exit(-1);
		}
		arg_Text = calloc(1,file_Stat.st_size+1);
		if (arg_Text != NULL)
		{
			if (fread(arg_Text,file_Stat.st_size,1,file_Fs) != 1)
			{
				fprintf(stderr,"%s: Could not read '%s'\n",
				 progname,arg_Source);
				exit(-1);
			}
		}
		fclose(file_Fs);
	}
	else
	{
		arg_Source = get_string_resource(dpy, XSUBLIM_ARG_PROGRAM,
		 "Executable");
		if (arg_Source != NULL)
		{
			char* exe_Command = calloc(1,strlen(arg_Source)+10);
			FILE* exe_Fs;

			if (exe_Command == NULL)
			{
				fprintf(stderr,
				 "%s: Could not allocate space for '%s'\n",
				 progname,arg_Source);
				exit(-1);
			}
			sprintf(exe_Command,"( %s ) 2>&1",arg_Source);

			exe_Fs = popen(exe_Command,"r");
			if (exe_Fs == NULL)
			{
				fprintf(stderr,"%s: Could not run '%s'\n",
				 progname,arg_Source);
				exit(-1);
			}
			arg_Text = calloc(1,XSUBLIM_PROGRAM_SIZE);
			if (arg_Text != NULL)
			{
				if (fread(arg_Text,1,XSUBLIM_PROGRAM_SIZE,
				 exe_Fs) <= 0)
				{
					fprintf(stderr,
					 "%s: Could not read output of '%s'\n",
					 progname,arg_Source);
					exit(-1);
				}
				if (
				 strstr(arg_Text,": not found") ||
				 strstr(arg_Text,": Not found") ||
				 strstr(arg_Text,": command not found") ||
				 strstr(arg_Text,": Command not found"))
				{
					fprintf(stderr,
					 "%s: Could not find '%s'\n",
					 progname,arg_Source);
					exit(-1);
				}
			}
			fclose(exe_Fs);
		}
		else
		{
			arg_Text =
			 get_string_resource(dpy, XSUBLIM_ARG_PHRASES,"Phrases");
			if (arg_Text != NULL)
			{
				arg_Text = strdup(arg_Text);
			}
		}
	}
	if (arg_Text != NULL)
	{
		while (((text_Phrase = strtok(arg_Text,"\n")) != NULL) &&
		 (text_Count < XSUBLIM_TEXT_COUNT))
		{
			arg_Text = NULL;
			text_List[text_Count] = text_Phrase;
			text_Count++;
		}
		text_List[text_Count] = NULL;
	}
	if (text_Count == 0)
	{
		fprintf(stderr,"%s: No text to display\n",progname);
		exit(-1);
	}

	/* Load the font */
	font_Font = XLoadQueryFont(dpy,
	 get_string_resource(dpy, XSUBLIM_ARG_FONT,"Font"));
	font_Index = 0;
	while ((font_Font == NULL) && (font_List[font_Index] != NULL))
	{
		font_Font = XLoadQueryFont(dpy,font_List[font_Index]);
		font_Index++;
	}
	if (font_Font == NULL)
	{
		fprintf(stderr,"%s: Couldn't load a font\n",progname);
		exit(-1);
	}

	/* Create the GCs */
	XGetWindowAttributes(dpy,win_Root,&attr_Win);
	gc_ValFore.font = font_Font->fid;
	gc_ValFore.foreground = get_pixel_resource(dpy,
                                                   attr_Win.colormap,
                                                   "foreground","Foreground");
	gc_ValFore.background = get_pixel_resource(dpy,
                                                   attr_Win.colormap,
                                                   "background","Background");
	gc_ValFore.subwindow_mode = IncludeInferiors;
	gc_GcFore = XCreateGC(dpy,win_Root,
	 (GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValFore);
	gc_ValBack.font = font_Font->fid;
	gc_ValBack.foreground = get_pixel_resource(dpy,
                                                   attr_Win.colormap,
                                                   "background","Background");
	gc_ValBack.background = get_pixel_resource(dpy,
                                                   attr_Win.colormap,
                                                   "foreground","Foreground");
	gc_ValBack.subwindow_mode = IncludeInferiors;
	gc_GcBack = XCreateGC(dpy,win_Root,
	 (GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValBack);

	/* Loop ------------------------------------------------------------ */
	while (Xsublim_Sig_Last == -1)
	{
		/* Once-per-phrase stuff ----------------------------------- */

		/* If we're waiting for a screensaver... */
		if (arg_FlagScreensaver != FALSE)
		{
			/* Find the screensaver's window */
			win_Root = xsublim_Ss_GetWindow(dpy);
			if (win_Root == 0)
			{
				usleep(30000000);
				continue;
			}
		}

		/* Pick the next phrase */
		if (arg_FlagRandom != FALSE)
		{
			text_Item = random()%text_Count;
			text_Index = 0;
		}
		while (text_Used[text_Item] != FALSE)
		{
			text_Index++;
			text_Item++;
			if (text_Index == text_Count)
			{
				text_Index = 0;
				memset(text_Used,0,sizeof(text_Used));
			}
			if (text_List[text_Item] == NULL)
			{
				text_Item = 0;
			}
		}
		text_Used[text_Item] = TRUE;
		strncpy(text_Text,text_List[text_Item],
		 XSUBLIM_TEXT_LENGTH);
		text_Phrase = text_Text;

		/* Run through the phrase */
		while (((text_Word = strtok(text_Phrase," \t")) != NULL) &&
		 (Xsublim_Sig_Last == -1))
		{
			text_Phrase = NULL;

			/* Once-per-word stuff ----------------------------- */

			/* Find the text's position */
			XGetWindowAttributes(dpy,win_Root,&attr_Win);
			text_Length = strlen(text_Word);
			text_Width = XTextWidth(font_Font,text_Word,
			 text_Length)+XSUBLIM_TEXT_OUTLINE*2;
			text_Height = font_Font->ascent+font_Font->descent+1+
			 XSUBLIM_TEXT_OUTLINE*2;
			if (arg_FlagCenter == FALSE)
			{
				text_X = random()%(attr_Win.width-text_Width);
				text_Y = random()%(attr_Win.height-
				 text_Height);
			}
			else
			{
				text_X = (attr_Win.width/2)-(text_Width/2);
				text_Y = (attr_Win.height/2)-(text_Height/2);
			}

			/* Find the image's position (and pad it out slightly,
			   otherwise bits of letter get left behind -- are
			   there boundry issues I don't know about?) */
			image_X = text_X-16;
			image_Y = text_Y;
			image_Width = text_Width+32;
			image_Height = text_Height;
			if (image_X < 0)
			{
				image_X = 0;
			}
			if (image_Y < 0)
			{
				image_Y = 0;
			}
			if (image_X+image_Width > attr_Win.width)
			{
				image_Width = attr_Win.width-image_X;
			}
			if (image_Y+image_Height > attr_Win.height)
			{
				image_Height = attr_Win.height-image_Y;
			}

			/* Influence people for our own ends --------------- */

			/* Grab the server -- we can't let anybody draw over
			   us */
			XSync(dpy,FALSE);
			XGrabServer(dpy);
			XSync(dpy,FALSE);

			/* Set up an error handler that ignores BadMatches --
			   since the screensaver can take its window away at
			   any time, any call that uses it might choke */
			Xsublim_Sh_Status = 0;
			Xsublim_Sh_Handler =
			 XSetErrorHandler(xsublim_Sh_Handler);

			/* Save the current background */
			image_Image = XGetImage(dpy,win_Root,image_X,
			 image_Y,image_Width,image_Height,~0L,ZPixmap);

			/* If we've successfully saved the background... */
			if (image_Image != NULL)
			{
				if (Xsublim_Sh_Status == 0)
				{
					/* Draw the outline */
					if (arg_FlagOutline != FALSE)
					{
						for (text_OutlineIndex = 0;
						 text_Outline[
						 text_OutlineIndex].outline_X
						 != 0;text_OutlineIndex++)
						{
							/* Y'know, eight
							   character tabs and
							   descriptive variable
							   names become
							   annoying at some
							   point... */
							XDrawString(
							 dpy,
							 win_Root,gc_GcBack,
							 text_X+text_Outline[
							 text_OutlineIndex].
							 outline_X*
							 XSUBLIM_TEXT_OUTLINE,
							 text_Y+
							 (font_Font->ascent)+
							 text_Outline[
							 text_OutlineIndex].
							 outline_Y*
							 XSUBLIM_TEXT_OUTLINE,
							 text_Word,
							 text_Length);
						}
					}

					/* Draw the word */
					XDrawString(dpy,win_Root,
					 gc_GcFore,text_X,
					 text_Y+(font_Font->ascent),text_Word,
					 text_Length);
				}
				if (Xsublim_Sh_Status == 0)
				{
					/* Wait a bit */
					XSync(dpy,FALSE);
					if (Xsublim_Sig_Last == -1)
					{
						usleep(arg_DelayShow);
					}
	
					/* Restore the background */
					XPutImage(dpy,win_Root,
					 gc_GcFore,image_Image,0,0,image_X,
					 image_Y,image_Width,image_Height);
				}

				/* Free the image */
				XDestroyImage(image_Image);
			}

			/* Restore the error handler, ungrab the server */
                        XSync(dpy,FALSE);
			XSetErrorHandler(Xsublim_Sh_Handler);
			XUngrabServer(dpy);
                        XSync(dpy,FALSE);

			/* Pause between words */
			if (Xsublim_Sig_Last == -1)
			{
				usleep(arg_DelayWord);
			}
		}

		/* Pause between phrases */
		if (Xsublim_Sig_Last == -1)
		{
			usleep(random()%(arg_DelayPhraseMax-
			 arg_DelayPhraseMin+1)+arg_DelayPhraseMin);
		}
	}

	/* Exit ------------------------------------------------------------ */
	for (sig_Number = 0;sig_Signal[sig_Number] != -1;sig_Number++)
	{
		signal(sig_Number,SIG_DFL);
	}
	kill(getpid(),Xsublim_Sig_Last);

	return 0;
}
コード例 #20
0
static int check_xkeysymdb(Display *display, bool verbose)
{
    if (verbose)
    {
	(void) xlibdir(display, verbose);
    }

    if (verbose)
    {
	std::cout << "Checking for XKeysymDB... ";
	std::cout.flush();
    }

    String me, my_class;
    XtGetApplicationNameAndClass(display, &me, &my_class);

    string xkeysymdb;

    {
	const _XtString s = getenv("XKEYSYMDB");
	if (s != 0)
	    xkeysymdb = s;
    }

    if (xkeysymdb.empty())
    {
	String s = XtResolvePathname(display, "", "XKeysymDB", "",
				     (String)0, Substitution(0), 0, 
				     XtFilePredicate(0));
	if (s != 0)
	    xkeysymdb = s;
	XtFree(s);
    }

    if (!xkeysymdb.empty())
    {
	if (verbose)
	{
	    std::cout << xkeysymdb << "\n";
	    std::cout.flush();
	}

	// Fix it now
	static string env;
	env = "XKEYSYMDB=" + xkeysymdb;
	putenv(CONST_CAST(char*,env.chars()));

	return 0;			// Okay
    }

    if (xlibdir(display) != 0)
    {
	string path = string(xlibdir(display)) + "/XKeysymDB";
	if (is_file(path))
	{
	    if (verbose)
	    {
		std::cout << path << "\n"
		     << "Note: this is not the default path compiled into " 
		     << me << ".\n"
		     << "    To avoid having " << me 
		     << " determine this setting each time it is started,\n"
		     << "    please set the XKEYSYMDB "
		     << "environment variable to\n"
		     << "    " << quote(path) << ".\n";
		std::cout.flush();
	    }

	    // Fix it
	    static string env;
	    env = "XKEYSYMDB=" + path;
	    putenv(CONST_CAST(char*,env.chars()));
	    return 0;
	}
    }