Пример #1
0
void XsComponent::_setResources (Widget w, const String *resources)
{
   assert (w != 0);
   
   XrmDatabase rdb = 0;
   const int bufSize = 200;
   char  buffer[bufSize];
   int   loop;

// Create an empty resource database

   rdb = XrmGetStringDatabase ("");

// Add the component resources

   loop = 0;
   while (resources[loop] != 0)
   {
      sprintf (buffer, "*%s%s\n", _name, resources[loop++]);
      assert (strlen (buffer) < bufSize);
      XrmPutLineResource (&rdb, buffer);
   }
   
// Merge these resources into the database

   if (rdb != 0)
   {
      XrmDatabase db = XtDatabase (XtDisplay (w));
      XrmCombineDatabase (rdb, &db, FALSE);
   }
}
Пример #2
0
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);
}
Пример #3
0
/*
* Not yet used but may be useful.
*
*/
void
wxSetDefaultResources (const Widget w, const char **resourceSpec, const char *name)
{
    int i;
    Display *dpy = XtDisplay (w);    // Retrieve the display pointer

    XrmDatabase rdb = NULL;    // A resource data base

    // Create an empty resource database
    rdb = XrmGetStringDatabase ("");

    // Add the Component resources, prepending the name of the component

    i = 0;
    while (resourceSpec[i] != NULL)
    {
        char buf[1000];

        sprintf (buf, "*%s%s", name, resourceSpec[i++]);
        XrmPutLineResource (&rdb, buf);
    }

    // Merge them into the Xt database, with lowest precendence

    if (rdb)
    {
#if (XlibSpecificationRelease>=5)
        XrmDatabase db = XtDatabase (dpy);
        XrmCombineDatabase (rdb, &db, False);
#else
        XrmMergeDatabases (dpy->db, &rdb);
        dpy->db = rdb;
#endif
    }
}
Пример #4
0
/* The first time we grab an image, do it the default way.
   The second and subsequent times, add "-no-desktop" to the command.
   That way we don't have to watch the window un-map 5+ times in a row.
   Also, we end up with the desktop on only one channel, and pictures
   on all the others (or colorbars, if no imageDirectory is set.)
 */
static void
hack_resources (Display *dpy)
{
#ifndef HAVE_JWXYZ
  static int count = -1;
  count++;

  if (count == 0)
    return;
  else if (count == 1)
    {
      XrmDatabase db = XtDatabase (dpy);
      char *res = "desktopGrabber";
      char *val = get_string_resource (dpy, res, "DesktopGrabber");
      char buf1[255];
      char buf2[255];
      XrmValue value;
      sprintf (buf1, "%.100s.%.100s", progname, res);
      sprintf (buf2, "%.200s -no-desktop", val);
      value.addr = buf2;
      value.size = strlen(buf2);
      XrmPutResource (&db, buf1, "String", &value);
    }
#endif /* HAVE_JWXYZ */
}
Пример #5
0
void InitPreferenceDB()
{    
  int i;
  char *hdir;
  XrmDatabase db;

  pref_db.dpyPrefs = dpyPrefs;
  pref_db.winPrefs = winPrefs;
  pref_db.cliPrefs = cliPrefs;
  pref_db.propPrefs = propPrefs;
  pref_db.treePrefs = treePrefs;
  

  /* 
   * if an .xqsrc rcfile doesnt exist in the users home directory create one
   */
  hdir = getenv( "HOME" );
  rcfile = XtMalloc( strlen(hdir) + strlen(RCFILE) + 1 );
  sprintf( rcfile, "%s/%s", hdir, RCFILE );

  db = XtDatabase( XtDisplay(appshell) ); 
  for( i=0; i<XtNumber(MiscRes); i++ ) 
       XrmPutLineResource( &db, MiscRes[i] );

  pref_db.db = XrmGetFileDatabase( rcfile );
  GetPrefFromDB();  

}
Пример #6
0
void MotifUI::SetDefaultResources(const Widget,
			          const String *resources)
{
   XrmDatabase rdb = NULL;
   int         i;

   rdb = XrmGetStringDatabase("");

   i = 0;
   while (resources[i])
    {
      char *buf = new char[1000];

      sprintf(buf, "%s%s", _name, resources[i]);
      XrmPutLineResource(&rdb, buf);
      i++;

      delete [] buf;
    }
   if (rdb)
    {
      XrmMergeDatabases(XtDatabase(display), &rdb);
      XrmSetDatabase(display, rdb);
    }
}
Пример #7
0
Файл: xcutsel.c Проект: aosm/X11
int 
main(int argc, char *argv[])
{
    char label[100];
    Widget box, button;
    XtAppContext appcon;
    Widget shell;
    XrmDatabase rdb;

    XtSetLanguageProc(NULL, NULL, NULL);

    shell =
	XtAppInitialize( &appcon, "XCutsel", optionDesc, XtNumber(optionDesc),
			 &argc, argv, NULL, NULL, 0 );
    rdb = XtDatabase(XtDisplay(shell));

    if (argc != 1) Syntax(argv[0]);

    XtGetApplicationResources( shell, (XtPointer)&options,
			       resources, XtNumber(resources),
			       NULL, ZERO );

    options.value = NULL;
    XmuInternStrings( XtDisplay(shell), &options.selection_name, ONE,
		      &options.selection );

    box = XtCreateManagedWidget("box", boxWidgetClass, shell, NULL, ZERO);

    button =
	XtCreateManagedWidget("quit", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, Quit, NULL );

    /* %%% hack alert... */
    sprintf(label, "*label:copy %s to %d",
	    options.selection_name,
	    options.buffer);
    XrmPutLineResource( &rdb, label );

    button =
	XtCreateManagedWidget("sel-cut", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, GetSelection, NULL );

    sprintf(label, "*label:copy %d to %s",
	    options.buffer,
	    options.selection_name);
    XrmPutLineResource( &rdb, label );

    button =
	XtCreateManagedWidget("cut-sel", commandWidgetClass, box, NULL, ZERO);
	XtAddCallback( button, XtNcallback, GetBuffer, (XtPointer)&state );
 	state.button = button;
	state.is_on = False;
   
    XtRealizeWidget(shell);
    XtAppMainLoop(appcon);
    exit(0);
}
Пример #8
0
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;
}
Пример #9
0
/* Kludge to add "-v" to invocation of "xscreensaver-getimage" in -debug mode
 */
static void
hack_resources (Display *dpy)
{
# ifndef HAVE_COCOA
  char *res = "desktopGrabber";
  char *val = get_string_resource (dpy, res, "DesktopGrabber");
  char buf1[255];
  char buf2[255];
  XrmValue value;
  XrmDatabase db = XtDatabase (dpy);
  sprintf (buf1, "%.100s.%.100s", progname, res);
  sprintf (buf2, "%.200s -v", val);
  value.addr = buf2;
  value.size = strlen(buf2);
  XrmPutResource (&db, buf1, "String", &value);
# endif /* !HAVE_COCOA */
}
char *
get_string_resource (Display *dpy, char *res_name, char *res_class)
{
  XrmValue value;
  char	*type;
  char full_name [1024], full_class [1024];
  strcpy (full_name, progname);
  strcat (full_name, ".");
  strcat (full_name, res_name);
  strcpy (full_class, progclass);
  strcat (full_class, ".");
  strcat (full_class, res_class);
  if (XrmGetResource (XtDatabase (dpy), full_name, full_class, &type, &value))
    {
      char *str = (char *) malloc (value.size + 1);
      strncpy (str, (char *) value.addr, value.size);
      str [value.size] = 0;
      return str;
    }
  return 0;
}
Пример #11
0
void XsComponent::_setResources (Widget w, const String *resources)
{
   assert (w != 0);
   
   XrmDatabase rdb = 0;
   const int bufSize = 200;
   char  buffer[bufSize];
   int   loop;

// Create an empty resource database

   rdb = XrmGetStringDatabase ("");

// Add the component resources

   loop = 0;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
   while (resources[loop] != 0)
   {
      sprintf (buffer, "*%s%s\n", _name, resources[loop++]);
      assert (strlen (buffer) < bufSize);
      XrmPutLineResource (&rdb, buffer);
   }
   
// Merge these resources into the database

   if (rdb != 0)
   {
      XrmDatabase db = XtDatabase (XtDisplay (w));
      XrmCombineDatabase (rdb, &db, FALSE);
   }
}
Пример #12
0
static void restore_state(
Widget		w,
XtPointer	client_data,
XtPointer	call_data)
{
    Widget		topl = (Widget) client_data;
    XmFileSelectionBoxCallbackStruct
	*cbs = (XmFileSelectionBoxCallbackStruct *) call_data;
    FILE		*fp;
    String		filestr;
    XrmDatabase 	database;
    SaveRestoreList	*svl=save_list;

    /* get the resource file name */
    if( (fp = HGU_XmGetFilePointer( w, cbs->value, cbs->dir, "r" )) == NULL )
	return;

    /* merge the file database with the application database */
    if( (filestr = HGU_XmGetFileStr( w, cbs->value, cbs->dir )) ){
	database = XtDatabase(XtDisplay(topl));
	XrmCombineFileDatabase(filestr, &database, True);
	XtFree( filestr );
    }

    /* read and set resources */
    restore_state_from_file( topl, fp );

    /* call registered restore_state procedures */
    while( svl != NULL ){

	if( svl->restore_func != NULL )
	    (*svl->restore_func)( svl->widget, svl->restore_data, fp );

	svl = svl->next_data;
    }
	    
    fclose( fp );
    return;
}
Пример #13
0
/*
 * Read the user preferences from xdvirc_filename and merge them into the
 * current resource database *and* into m_user_db so that all of them are
 * saved again when xdvi exits.
 */
void
read_user_preferences(Widget toplevel, const char *filename)
{
    char *fullpath;
    XrmDatabase db;
#if XtSpecificationRelease == 4
    XrmDatabase file_db;
#endif

    fullpath = get_xdvirc_path(filename);
    TRACE_GUI((stderr, "Reading resources from `%s'", fullpath));
    db = XtDatabase(XtDisplay(toplevel));
    
#if XtSpecificationRelease == 4
    file_db  = XrmGetFileDatabase(fullpath);
    XrmMergeDatabases(file_db, &db);
    XrmMergeDatabases(file_db, &m_user_db);
#else /* Xt >= X11R5 */
    XrmCombineFileDatabase(fullpath, &db, True);
    XrmCombineFileDatabase(fullpath, &m_user_db, True);
#endif
    free(fullpath);
}
Пример #14
0
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
   else
        name = nameBuf;

   sprintf (name, "%s*%s",
        _DtEnv_NULL_GUARD( _DtApplicationName) , _DTENV_MAP_RESOURCE_NAME);

   bytesNeeded = strlen(_DTENV_MAP_RESOURCE_CLASS)
                       + strlen(_DtApplicationClass) + 4;
   if ( bytesNeeded > _DtEnv_MAX_BUF_SIZE )
        class = XtMalloc(bytesNeeded);
   else
        class = classBuf;
   sprintf (class, "%s*%s",
        _DtEnv_NULL_GUARD(_DtApplicationClass) , _DTENV_MAP_RESOURCE_CLASS);

   db = XtDatabase (_DtDisplay);
   if (XrmGetResource (db, nameBuf, classBuf, &rep_type, &resource_value))
      mapInfo = (char *) resource_value.addr;
   else
      mapInfo = (char *) NULL;

   if ( name != nameBuf )
        XtFree(name);
   if ( class != classBuf )
        XtFree(class);

   if (mapInfo)
	return( XtNewString( mapInfo ) );
   else
	return( (char *) NULL );
}
Пример #16
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;
}
Пример #17
0
/************************************************************************
**
** GetPaletteDefinition -
**  Query the database for the Dtstyle.paletteDirectories resource
**  Use Dtstyle default (Default) if not specified.
**  Search the directories for the palette in reverse order
**
************************************************************************/
struct _palette * 
GetPaletteDefinition( 
Display *dpy,
int     screen_number,
char    *palette)

{
    struct _palette *paletteDef;
    char *str_type_return;
    XrmValue value_return;
    XrmDatabase db;
    Boolean match = False;
    char *palettePath;
    char *path;
    char *p, *d;
    char *home;
    char dir[256];
                    

    if (FindPalette (palette, SYSTEM_PALETTE_DIR))
    {
       /* 
	* First look for palette in the system location
        */
        palettePath = (char *) SRV_MALLOC (strlen(SYSTEM_PALETTE_DIR) + 1 );
        strcpy(palettePath, SYSTEM_PALETTE_DIR);
        match = True;
    }
    else if (FindPalette (palette, CONFIG_PALETTE_DIR))
    {
       /* 
	* Next check the local config location
        */
        palettePath = (char *) SRV_MALLOC (strlen(CONFIG_PALETTE_DIR) + 1 );
        strcpy(palettePath, CONFIG_PALETTE_DIR);
        match = True;
    }
    else 
    {
	palettePath = NULL;
    }

    /*  Get Dtstyle.paletteDirectories value */
    db = XtDatabase(dpy);
    if (XrmGetResource (db, "dtstyle.paletteDirectories",
                            "Dtstyle.PaletteDirectories",
                            &str_type_return, &value_return))
    {
        /* Make Local Copy of string */
        path = (char *) SRV_MALLOC( value_return.size + 1 );
        strcpy (path, value_return.addr);
    }
    else 
    {
        path = NULL;
    }

    /* Look for palette in paletteDirectories */
    if (path != NULL)
    {
        /* Loop through paletteDirectories looking in each directory
         * till we find the palette file. Take first occurrance.
         * Copy directory name into dir.  Look for NULL or space 
         */

        p = path;
        while (*p != '\0')
        {
            d = dir;
            while (*p != ' ' && *p != '\0')
                *d++ = *p++;
            *d = '\0';
            if (FindPalette (palette, dir))
            {
                palettePath = (char *)SRV_REALLOC(palettePath, 
                                                strlen(SYSTEM_PALETTE_DIR) + 1);
                strcpy(palettePath, dir);
                match = True;
                break;
            }
        }
    }
        
    /* Look for palette in $HOME/.dt/palettes */
    /* If there is a duplicate, take it */

    if ((home=getenv(HOME)) == NULL)
      home="";
    path = (char *) SRV_REALLOC (path, 
        strlen(home) + strlen(USER_PALETTE_DIR) + 1);
    strcpy(path, home);
    strcat(path, USER_PALETTE_DIR);

    if (FindPalette (palette, path))
    {
        palettePath = (char *) SRV_REALLOC (palettePath, strlen(path) + 1 );
        strcpy(palettePath, path);
        match = True;
    }
    
    if (match)
    {
        /* Parse the data from the palette file */
        paletteDef = (struct _palette *) ReadPaletteFile(dpy, 
                                                         screen_number, 
                                                         palettePath,
                                                         palette);
    } 
    else /* default to system Default */
    {
        palettePath = (char *) SRV_REALLOC (palettePath,
                                            strlen(SYSTEM_PALETTE_DIR) + 1);
        strcpy(palettePath, SYSTEM_PALETTE_DIR);
        paletteDef = (struct _palette *)ReadPaletteFile(dpy, 
                                                        screen_number, 
                                                        palettePath,
                                                        DEFAULT_PALETTE);
    }

    if (path != NULL)
        SRV_FREE(path);
    if (palettePath != NULL)
        SRV_FREE(palettePath);

    return (paletteDef);

}
Пример #18
0
static void 
getDtwmValues( )
{
    char *str_type_return;
    XrmValue value_return;
    XrmValue    cvt_value;
    XrmDatabase db;
    Boolean status;
    char *string;

    db = XtDatabase(style.display);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}
Пример #19
0
/*-------------------------------------------------------------------------*/
int main(
int argc,
char **argv 
) {
   Widget StartupWindow = 0;
   Arg  args[10];
   Cardinal ac = 0;
#ifdef L10N
   char *lang;
#endif   
/*    static char app_name[1024]; */

   int i;
   XrmDatabase qmon_database;
   static char progname[256];

   DENTER_MAIN(TOP_LAYER, "qmon_main");

#ifndef L10N
   setlocale(LC_ALL, "C");
   putenv("LANG=C"); 
   putenv("LC_ALL=C"); 
#endif

   /* INSTALL SIGNAL HANDLER */
   qmonInstSignalHandler();

   strcpy(progname, argv[0]);

   /* GENERAL SGE SETUP */
   if (!(argc > 1 && !strcmp(argv[1], "-help"))) {
      qmonInitSge(&ctx, progname, 0);
   } else {  
      /* -help */
      qmonInitSge(&ctx, progname, 1);
   }

   SGE_ROOT = ctx->get_sge_root(ctx);

   /*
   ** Attention !!! Change the XtMalloc() above if you add additional args
   */
   ac = 0;
   XtSetArg(args[ac], XmtNconfigDir, SGE_ROOT); ac++;
   XtSetArg(args[ac], XmtNconfigPath, "%R/locale/%L/%N%S:%R/locale/%l/%N%S:%R/locale/%l_%t.%c/%N%S:%R/qmon/%N%S"); ac++;
/*    XtSetArg(args[ac], XmtNpixmapFilePath, "%R/qmon/PIXMAPS/%N.xpm"); ac++; */
/*    XtSetArg(args[ac], XmtNcontextHelpFile, "qmon_help"); ac++; */
   XtSetArg(args[ac], XtNtitle, "QMON +++ Main Control"); ac++;
   
   /* 
   ** SETUP XMT, here qmon_version is checked, 
   ** so here an exit is possible 
   */
   AppShell = XmtInitialize( &AppContext, APP_NAME,
                             NULL, 0,
                             &argc, argv, 
                             qmon_fallbacks,
                             args, ac);

   sigint_id = XtAppAddSignal(AppContext, sigint_callback, NULL);
   
#if 0
   /*
   ** protocoll the actions performed by qmon
   */
   XtAppAddActionHook(AppContext, TraceActions, NULL);
#endif

#ifdef L10N
   /*
   ** Internationalization:
   ** The qmon_messages.ad file is installed under 
   ** $SGE_ROOT/qmon/locale/<LANG>/qmon_messages.ad
   ** Read in the _Messages_ catalogue
   */
   if (((lang = getenv("LC_MESSAGES")) || (lang = getenv("LC_ALL")) ||
         (lang = getenv("LANG"))) && lang && strcasecmp(lang, "POSIX") &&
         strcasecmp(lang, "C")) {
      DPRINTF(("lang: '%s'\n", lang));
      if (!strcasecmp(lang, "relabel"))   
         lang = "C";
      XmtLoadResourceFile(AppShell, "qmon_messages", False, True);
   }   
#endif

#if 0   
   strcpy(app_name, "QMON +++ Main Control");
   if (strcmp(uti_state_get_default_cell(), "default")) {
      strcat(app_name, " @ ");
      strncat(app_name, uti_state_get_default_cell(), 1000);
   }

   XtVaSetValues(AppShell, 
              XtNtitle, XmtLocalize(AppShell, app_name,
                                    "QMON +++ Main Control"), NULL);
#endif   
   XtVaSetValues(AppShell, 
              XtNtitle, XmtLocalize(AppShell, "QMON +++ Main Control",
                                    "QMON +++ Main Control"), NULL);
   
   /*
   ** we must shift the usage here for internationalization
   */
   if (helpset) {
      qmonUsage(AppShell);
      qmonExitFunc(0);
   }
   
   /* 
   ** get the dialog resource files, they override any settings from the
   ** Qmon app default file concerning dialogue descriptions
   */
   qmon_database = XtDatabase(XtDisplay(AppShell));
   for (i=0; qmon_dialogs[i]; i++) {
      XrmPutLineResource(&qmon_database, qmon_dialogs[i]);
   }
#if 0
   /*
   ** Debugging:
   ** write contents of Resource DB to file DB.TXT in cwd
   */
   XrmPutFileDatabase(qmon_database, "DB.TXT");
#endif   

   /* 
   ** read qmon preferences file ~/.qmon_preferences, it contains
   ** customization info for Queue and Job Control dialogues
   */
   qmonReadPreferences();
   
   /*
   ** display of startup screen ?
   */
   if (!nologo) {
      /* show the user we're starting up */
      StartupWindow = qmonStartupWindow(AppShell);
   }
   
   /* 
   ** INITIALIZE Graphics Contexts 
   */
   qmonCreateGC(AppShell);

   /* 
   ** Allocate Pixel values 
   */
   qmonAllocColor(AppShell);

   /* 
   ** Cache all Icons 
   */
   qmonLoadIcons();

   /* 
   ** set the close button callback 
   ** cause the close button to call the qmonExitCB() 
   ** set the icon and iconName after qmonLoadIcons()
   */
   XmtCreatePixmapIcon(AppShell, qmonGetIcon("mcicon"), None);
   XtVaSetValues(AppShell, XtNiconName, "qmon:Main Control", NULL);
   XmtAddDeleteCallback(AppShell, XmDO_NOTHING, qmonExitCB, NULL);

   /* 
   ** CREATE MainControl 
   */
   MainControl = qmonCreateMainControl(AppShell);

   /* 
   ** install context help 
   */
   XmtHelpInstallContextHelp(AppShell, XmtHelpContextHelpCallback, NULL);
/*    XmtHelpParseFile(AppShell, "qmon_help"); */


   /* 
   ** initialize QmonMirrorList entries 
   */
   qmonMirrorListInit();
   
   /* 
   ** setup timers 
   */
   qmonStartPolling(AppContext);
   
#ifdef HAS_EDITRES
    /* 
    ** Plug in editres protocol handler 
    */
    XtAddEventHandler (AppShell, (EventMask)0, True,
        _XEditResCheckMessages, (XtPointer)NULL);
#endif


   /* 
   ** Popdown startup screen and destroy it
   */
   if (!nologo) {
      sleep(1);
      XtDestroyWidget(StartupWindow);
   }   


   XtRealizeWidget(AppShell);
   XtAppMainLoop(AppContext);

   return 0;
}
Пример #20
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);
}
Пример #21
0
/* save-restore initialisation procedure */
void HGU_XmSaveRestoreInit(
Widget	topl,
int	*argc,
char	**argv)
{
    XmString		xmstr;
    Visual		*visual;
    Arg			arg[1];
    static int		initialised=0;

    /* check initialisation */
    if( initialised )
	return;
    initialised = 1;

    /* check command line for -state option */
    if( *argc > 2 && argv != NULL ){
	int 	i;
	FILE	*fp;
	for(i=0; i < *argc; i++){
	    if( strcmp(argv[i], "-state") == 0 && i < (*argc-1) ){
		int	j;

		XrmDatabase database = XtDatabase(XtDisplay(topl));

		/* merge the file database with the application database */
		XrmCombineFileDatabase(argv[i+1], &database, True);

		/* set any topl widget resources */
		if( (fp = fopen(argv[i+1], "r")) != NULL ){
		    restore_state_from_file( topl, fp );
		    fclose( fp );
		} else {
		    fprintf(stderr,
			    "HGU_XmSaveRestoreInit: can't open file %s\n",
			    argv[i+1]);
		}

		/* remove the -state option from the list */
		for(j=i+2; j < *argc; j++)
		    argv[j-2] = argv[j];
		*argc -= 2;
		i--;
	    }
	}
    }


    /* default save procedure */
    default_save_func = default_save;
    default_save_data = XtName( topl );

    /* create save_state and restore_state file selection dialogs */
    /* get the visual explicitly */
    visual = HGU_XmWidgetToVisual( topl );
    XtSetArg(arg[0], XmNvisual, visual);
    if( argv == NULL )
	XtVaGetValues(topl, XtNargv, &argv, NULL);
    save_state_dialog =
	XmCreateFileSelectionDialog( topl, "save_state_dialog", arg, 1);
    sprintf(argv_0, "%s - save state", argv[0]);
    xmstr = XmStringCreateSimple( argv_0 );
    XtVaSetValues( save_state_dialog, XmNdialogTitle, xmstr, NULL );
    XmStringFree( xmstr );

    XtAddCallback(save_state_dialog, XmNcancelCallback, 
                  (void (*)()) XtUnmanageChild, NULL);
    XtAddCallback(save_state_dialog, XmNokCallback, 
                  (void (*)()) XtUnmanageChild, NULL);
    XtAddCallback(save_state_dialog, XmNokCallback, 
                  save_state, (XtPointer) topl);

    restore_state_dialog =
	XmCreateFileSelectionDialog( topl, "restore_state_dialog", arg, 1);
    sprintf(argv_0, "%s - restore state", argv[0]);
    xmstr = XmStringCreateSimple( argv_0 );
    XtVaSetValues( restore_state_dialog, XmNdialogTitle, xmstr, NULL );
    XmStringFree( xmstr );

    XtAddCallback(restore_state_dialog, XmNcancelCallback, 
                  (void (*)()) XtUnmanageChild, NULL);
    XtAddCallback(restore_state_dialog, XmNokCallback, 
                  (void (*)()) XtUnmanageChild, NULL);
    XtAddCallback(restore_state_dialog, XmNokCallback, 
                  restore_state, (XtPointer) topl);

    sprintf( argv_0, "%s", argv[0] );
    return;
}