void main( int argc, char **argv ) { Display *display; int result; #ifdef USERHELP malloc_check(1); malloc_trace(0); #endif XtAppContext app; /* Initialize the toolkit and open the display */ XtToolkitInitialize(); app = XtCreateApplicationContext(); display = XtOpenDisplay(app, NULL, argv[0], "Customize", NULL, 0, &argc, argv); /* Go register the DT error handler */ XeProgName = argv[0]; result = InitializeDtcolor(display, DEFAULT_SESSION); if(result != 0) exit(0); XtAppMainLoop(app); }
static void ChildPrintToFile(String display_name, XPContext pcontext, FILE *file, char *file_name, int pipe, String application_name, String application_class) { FileDescRec *file_desc; XtAppContext app_context; int argc = 0; String argv[] = { NULL }; Display *display; file_desc = (FileDescRec *) XtMalloc(sizeof(FileDescRec)); file_desc->file_name = XtNewString(file_name); file_desc->file = file; file_desc->pipe = pipe; app_context = XtCreateApplicationContext(); if ((display = XtOpenDisplay(app_context, display_name, application_name, application_class, NULL, 0, &argc, argv)) == NULL) { _exit(1); } XpGetDocumentData(display, pcontext, PrintToFileProc, FinishProc, (XPointer) file_desc); XtAppMainLoop(app_context); _exit(0); }
int main (int argc, char *argv[]) { XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL ); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication", NULL, 0, &argc, argv); if (!display) { printf("%s: can't open display, exiting...\n", argv[0]); exit (-1); } create_shell ( display, argv[0], argc, argv ); XtRealizeWidget (shell); /* Note: the following values are the result of * querying the current geometry. */ { static XtWidgetGeometry Expected[] = { CWWidth | CWHeight , 361, 266, 74, 400, 0,0,0, /* form */ CWWidth | CWHeight | CWX | CWY, 0, 0, 74, 260, 0,0,0, /* list1SW */ CWWidth | CWHeight | CWX | CWY, 0, 0, 74, 260, 0,0,0, /* list1 */ CWWidth | CWHeight | CWX | CWY, 0, 260, 74, 140, 0,0,0, /* da */ }; /* toplevel should be replaced with to correct applicationShell */ PrintDetails(shell, Expected); } LessTifTestMainLoop(shell); exit (0); }
static void test_XtAppMainLoop_34715(void) { XtAppContext app; struct sigaction sa; XtToolkitInitialize(); app = XtCreateApplicationContext(); XtAppAddTimeOut(app, 1000, _Tick, app); /* AppTimeouts should finish and exit in 3 seconds. Give them 10 seconds just in case system is busy, then fail. */ sa.sa_handler = sigalrm; sa.sa_flags = SA_RESTART; sigemptyset (&sa.sa_mask); if (sigsetjmp(jump_env, 1) == 0) { sigaction(SIGALRM, &sa, NULL); alarm(10); XtAppMainLoop(app); } else { g_assert(XtAppGetExitFlag(app) == TRUE); g_assert(0 /* timed out */); } g_assert(XtAppGetExitFlag(app) == TRUE); XtDestroyApplicationContext(app); }
void Application::initialize(std::string name, int argc, char* argv[]) { String fallbacks[fallbackResources.size() + 1]; XtToolkitInitialize(); context = XtCreateApplicationContext(); for(unsigned int resourceIndex = 0; resourceIndex < fallbackResources.size(); resourceIndex++) { fallbacks[resourceIndex] = (char*)fallbackResources.at(resourceIndex).c_str(); } fallbacks[fallbackResources.size()] = NULL; XtAppSetFallbackResources(context, fallbacks); Application::name = name; display = XtOpenDisplay(context, NULL, name.c_str(), name.c_str(), NULL, 0, &argc, argv); if(display == NULL) { throw MotifException("Failed to open display"); } initialized = true; widget = XtAppCreateShell(Application::getName().c_str(), Application::getName().c_str(), applicationShellWidgetClass, Application::getDisplay(), NULL, 0); }
void main (int argc, char **argv) { XtAppContext context; Display *display; /* ** Initialize toolkit and open display. */ XtToolkitInitialize (); context = XtCreateApplicationContext(); /* ** Keep the same application name, so I don't have to muck around the ** Xdefaults file */ display = XtOpenDisplay (context, NULL, "phase", "Space", NULL, 0, &argc, argv); if (!display) { XtWarning("Space: Can't open display"); exit(0); } /* ** Create an event display panel */ DisplayEventFileSp(display, exit); /* ** Process events. */ XtAppMainLoop (context); }
void motif_init(QSP_ARG_DECL const char *progname) { const char *argv[1]; int argc=1; argv[0]=progname; the_dname = check_display(SINGLE_QSP_ARG); /* * initialize the Xt toolkit and create an application context * and shell */ XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL ); XtToolkitInitialize (); globalAppContext = XtCreateApplicationContext (); display = XtOpenDisplay (globalAppContext, the_dname, argv[0],"guimenu", NULL, 0, &argc, (char **)argv); if (!display) { fprintf(stderr, "can't open display\n"); return; } add_event_func(QSP_ARG motif_dispatch); // This is not really a motif-specific thing, // but we do this here because nav_panel_itp is // static to this file... if( nav_panel_itp == NO_ITEM_TYPE ){ init_nav_panels(SINGLE_QSP_ARG); add_genwin(QSP_ARG nav_panel_itp, &navp_genwin_funcs, NULL); } }
XtAppContext _XtDefaultAppContext() { register ProcessContext process = _XtGetProcessContext(); if (process->defaultAppContext == NULL) { process->defaultAppContext = XtCreateApplicationContext(); } return process->defaultAppContext; }
void serve_client(int socket) { XEvent event; XtToolkitInitialize(); app_context = XtCreateApplicationContext(); LispAction.string = "Lisp"; LispAction.proc = LispActionProc; XtAppAddActions(app_context, &LispAction, 1); string_token_tag = find_type_entry(ExtRStringToken); string_tag = find_type_entry(XtRString); xm_string_tag = find_type_entry(XmRXmString); enum_tag = find_type_entry(XtREnum); int_tag = find_type_entry(XtRInt); window_tag = find_type_entry(XtRWindow); boolean_tag = find_type_entry(XtRBoolean); widget_tag = find_type_entry(XtRWidget); function_tag = find_type_entry(XtRFunction); callback_reason_tag = find_type_entry(ExtRCallbackReason); event_tag = find_type_entry(ExtREvent); resource_list_tag = find_type_entry(ExtRResourceList); translation_table_tag = find_type_entry(XtRTranslationTable); accelerator_table_tag = find_type_entry(XtRAcceleratorTable); atom_tag = find_type_entry(XtRAtom); font_list_tag = find_type_entry(XmRFontList); string_table_tag = find_type_entry(XtRStringTable); xm_string_table_tag = find_type_entry(XmRXmStringTable); int_list_tag = find_type_entry(ExtRIntList); cursor_tag = find_type_entry(XtRCursor); client_socket = socket; greet_client(socket); XtAppAddInput(app_context, socket, (XtPointer)XtInputReadMask, (XtInputCallbackProc)get_input, (XtPointer)NULL); XtAppSetErrorHandler(app_context, MyErrorHandler); XtAppSetWarningHandler(app_context, MyWarningHandler); /* Here is where we want to return on errors */ if( setjmp(env) ) { printf("Attempting to recover from error.\n"); fflush(stdout); } while( !terminate_server ) { XtAppNextEvent(app_context, &event); XtDispatchEvent(&event); } close(socket); XtDestroyApplicationContext(app_context); exit(0); }
/************************************************************** * main: **************************************************************/ int main(int argc, char **argv) { XtAppContext app_context; Display * display; Widget top_level; char * aclass = "XmdDaInput"; char name[132]; char ** temp_argv = argv; (void) strncpy(name, base(argv[0]), 132); /* handle the '-name' option */ while (*temp_argv) { if (strcmp(*temp_argv, "-name") == 0) { (void) strncpy(name, *++temp_argv, 132); break; } temp_argv++; } /* Initialize the X Intrinsics */ XtToolkitInitialize(); /* Set up language environment */ XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); /* create application context */ app_context = XtCreateApplicationContext(); /* open up one display */ display = XtOpenDisplay(app_context, NULL, name, aclass, (XrmOptionDescRec *)NULL, 0, &argc, argv); if (!display) { (void) fprintf(stderr, "Unable to open display\n"); exit(0); } /* Create the user interface */ top_level = DaCreateGui(name, aclass, argc, argv, display); if (top_level == NULL) { (void) fprintf(stderr, "Unable to create user interface\n"); exit(1); } /* Realize and start event dispatching */ XtRealizeWidget(top_level); XtAppMainLoop(app_context); return 0; /* make compiler happy */ }
static void XInit(int *argc, char ***argv) { XtToolkitInitialize(); xi.context = XtCreateApplicationContext(); XtAppSetFallbackResources(xi.context, fallback_resources); xi.disp = XtOpenDisplay(xi.context, NULL, "NMovie", "NMovie", NULL, 0, argc, *argv); if (!xi.disp) ErrorExit(ERROR_BAD_PARM,"Unable to open display"); shmext = XShmQueryExtension(xi.disp); xi.screenno = DefaultScreen(xi.disp); }
void imagesc(void *data, int x, int y, const char* type, double (*transf)(double), const char **colormap, char *title) { static XtAppContext context; Widget drawing_area; Widget toplevel; Atom wm_delete; XEvent event; XpmImage *xpmImage; Boolean exitFlag = False; static Display *display = NULL; Arg al[10]; int ac; int argc = 0; xpmImage = CreateXpmImage(data, x, y, type, transf, colormap); /* create the toplevel shell */ XtToolkitInitialize(); if (display == NULL) { context = XtCreateApplicationContext(); display = XtOpenDisplay(context, NULL, NULL, "", NULL, 0, &argc, NULL); } toplevel =XtAppCreateShell(title, "", applicationShellWidgetClass, display, NULL, 0); /* set window size. */ ac=0; XtSetArg(al[ac],XmNmaxWidth, x); ac++; XtSetArg(al[ac],XmNmaxHeight, y); ac++; XtSetArg(al[ac],XmNminWidth, x); ac++; XtSetArg(al[ac],XmNminHeight, y); ac++; XtSetArg(al[ac],XmNdeleteResponse, XmDO_NOTHING); ac++; XtSetValues(toplevel,al,ac); ac=0; drawing_area=XmCreateDrawingArea(toplevel,"drawing_area",al,ac); XtManageChild(drawing_area); XtAddCallback(drawing_area,XmNexposeCallback,draw_pixmap,(XtPointer) xpmImage); XtAddEventHandler(drawing_area, KeyReleaseMask, false, KeyAction, (XtPointer) &exitFlag); XtRealizeWidget(toplevel); wm_delete = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False); XmAddWMProtocolCallback(toplevel, wm_delete, quitCB, (XtPointer) &exitFlag); XmActivateWMProtocol(toplevel, wm_delete); while (!exitFlag) { XtAppNextEvent(context, &event); XtDispatchEvent(&event); } XtDestroyWidget(drawing_area); XtDestroyWidget(toplevel); free(xpmImage); }
XtEvents::XtEvents() { XtToolkitInitialize(); context = XtCreateApplicationContext(); int argc = qApp->argc(); XtDisplayInitialize( context, QX11Info::display(), qAppName().toLatin1(), QX11Info::appClass(), NULL, 0, &argc, qApp->argv()); connect( &timer, SIGNAL(timeout()), SLOT(idleProcess())); kapp->installX11EventFilter( this ); // No way to find out when to process Xt events, so poll :( // ... but only after enable() has been called self = this; }
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; }
int main (int argc, char **argv) { Widget app_shell; /* Add Xt support for i18n: locale */ XtSetLanguageProc(NULL, NULL, NULL); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, argv[0], "ArborSplash", NULL, 0, &argc, argv); if (!display) { printf("%s: can't open display, exiting...\n", argv[0]); exit (-1); } /* * Create a dummy application shell, and then hide it again so that the * splash screen can be a top-level screen for all applications. */ app_shell = XtAppCreateShell(".splash", "ArborSplash", applicationShellWidgetClass, display, NULL, 0); create_splash_shell(app_shell); XtUnmanageChild(splash_form); /* * Unmanage the OK button -- the window will pop itself down after * 5 seconds. */ XtUnmanageChild(splash_ok_btn); show_window(splash_shell, splash_form); XtAddEventHandler(splash_shell, VisibilityChangeMask, False, popup_splash, NULL); XtAppAddTimeOut(app_context, 5000, exit_splash, NULL); XtAppMainLoop(app_context); return(0); }
XtAppContext TclSetAppContext( XtAppContext appContext) { if (!initialized) { InitNotifier(); } /* * If we already have a context we check whether we were asked to set a * new context. If so, we panic because we try to prevent switching * contexts by mistake. Otherwise, we return the one we have. */ if (notifier.appContext != NULL) { if (appContext != NULL) { /* * We already have a context. We do not allow switching contexts * after initialization, so we panic. */ Tcl_Panic("TclSetAppContext: multiple application contexts"); } } else { /* * If we get here we have not yet gotten a context, so either create * one or use the one supplied by our caller. */ if (appContext == NULL) { /* * We must create a new context and tell our caller what it is, so * she can use it too. */ notifier.appContext = XtCreateApplicationContext(); notifier.appContextCreated = 1; } else { /* * Otherwise we remember the context that our caller gave us and * use it. */ notifier.appContextCreated = 0; notifier.appContext = appContext; } } return notifier.appContext; }
/*! Constructs a QApplication and initializes the Xt toolkit. The \a appclass, \a options, \a num_options, and \a resources arguments are passed on to XtAppSetFallbackResources and XtDisplayInitialize. Use this constructor when writing a new Qt application which needs to use some existing Xt/Motif widgets. */ KXtApplication::KXtApplication(int& argc, char** argv, const QCString& rAppName, bool allowStyles, bool GUIenabled, XrmOptionDescRec *options, int num_options, char** resources) : KApplication(argc, argv, rAppName, allowStyles, GUIenabled) { my_xt = TRUE; XtToolkitInitialize(); appcon = XtCreateApplicationContext(); if (resources) XtAppSetFallbackResources(appcon, (char**)resources); XtDisplayInitialize(appcon, qt_xdisplay(), name(), rAppName, options, num_options, &argc, argv); init(); }
QXtEventLoop::QXtEventLoop( const char *applicationClass, XtAppContext context, XrmOptionDescRec *options , int numOptions) { #if defined(QT_CHECK_STATE) if ( static_d ) tqWarning( "QXtEventLoop: should only have one QXtEventLoop instance!" ); #endif d = static_d = new QXtEventLoopPrivate; XtToolkitInitialize(); if ( context ) d->appContext = context; else d->ownContext = d->appContext = XtCreateApplicationContext(); d->applicationClass = applicationClass; d->options = options; d->numOptions = numOptions; }
void help_win(Widget widget, XtPointer client_data, XtPointer call_data) { Widget tL1, vpane, buttonbox; Widget close, txt; int one = 1; char *argv[2]; Display * dpy; if (help_context != NULL) return; argv[0] = "xsuprem"; argv[1] = NULL; help_context = XtCreateApplicationContext(); dpy = XtOpenDisplay(help_context, (String) NULL, NULL, "XSuprem", NULL, 0, &one, argv); if (dpy == NULL) XtErrorMsg("invalidDisplay","xtInitialize","XtToolkitError", "Can't Open display", (String *) NULL, (Cardinal *)NULL); tL1 = XtVaAppCreateShell( "XSupHelp", "XSuprem", applicationShellWidgetClass, dpy, XtNscreen, (XtArgVal)DefaultScreenOfDisplay(dpy), NULL ); vpane = XtVaCreateManagedWidget("vpane", panedWidgetClass, tL1, NULL); buttonbox = XtVaCreateManagedWidget("buttonbox", boxWidgetClass, vpane, NULL); /*Make the Help Button*/ close = XtVaCreateManagedWidget("Cancel", commandWidgetClass, buttonbox, NULL); XtAddCallback(close, XtNcallback, destroy_help, NULL); txt = XtVaCreateManagedWidget("help", asciiTextWidgetClass, vpane, XtNscrollVertical, XawtextScrollAlways, XtNtype, XawAsciiFile, /*XtNstring, "/home/helios0/law/src/xgraph/help",*/ NULL); XtRealizeWidget(tL1); }
void OnLibraryLoad() { // Tell X Threads are OK. XInitThreads(); #ifdef XT XtToolkitInitialize(); app_context = XtCreateApplicationContext(); #endif // Open local display. disp = XOpenDisplay(XDisplayName(NULL)); #ifdef DEBUG if (disp != NULL) { fprintf(stdout, "OnLibraryLoad(): XOpenDisplay successful.\n"); } else { fprintf(stderr, "OnLibraryLoad(): XOpenDisplay failure!\n"); } #endif Bool isAutoRepeat = False; #ifdef XKB // Enable detectable autorepeat. XkbSetDetectableAutoRepeat(disp, True, &isAutoRepeat); #else XAutoRepeatOn(disp); XKeyboardState kb_state; XGetKeyboardControl(disp, &kb_state); isAutoRepeat = (kb_state.global_auto_repeat == AutoRepeatModeOn); #endif #ifdef DEBUG if (isAutoRepeat) { fprintf(stdout, "OnLibraryLoad(): Successfully enabled detectable autorepeat.\n"); } else { fprintf(stderr, "OnLibraryLoad(): Could not enable detectable auto-repeat!\n"); } #endif }
EIF_POINTER xt_init () { /* Initialize Xt toolkit and application context * add action c_callback_on_trans to the list of * application actions, it will be called by any * new translations or accelerators. * Prepare the Xt toolkit and create a global * application context. */ XtAppContext gAppContext; static XtActionsRec actionTable [] = { {c_trans_routine, handle_translation}, }; XtToolkitInitialize (); gAppContext = XtCreateApplicationContext (); XtAppAddActions (gAppContext, actionTable, XtNumber (actionTable)); return (EIF_POINTER) gAppContext; }
int main (int argc, char **argv) { XtAppContext app_context; Display *display; /* Display */ XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL ); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication", NULL, 0, &argc, argv); if (!display) { printf("%s: can't open display, exiting...\n", argv[0]); exit (-1); } create_shell ( display, argv[0], argc, argv ); exit (0); }
/* Initial Xt plugin */ static void xt_client_init( XtClient * xtclient, Visual *xtvisual, Colormap xtcolormap, int xtdepth) { XtAppContext app_context; char *mArgv[1]; int mArgc = 0; /* * Initialize Xt stuff */ xtclient->top_widget = NULL; xtclient->child_widget = NULL; xtclient->xtdisplay = NULL; xtclient->xtvisual = NULL; xtclient->xtcolormap = 0; xtclient->xtdepth = 0; if (!xt_is_initialized) { #ifdef DEBUG_XTBIN printf("starting up Xt stuff\n"); #endif XtToolkitInitialize(); app_context = XtCreateApplicationContext(); if (fallback) XtAppSetFallbackResources(app_context, fallback); xtdisplay = XtOpenDisplay(app_context, gdk_get_display(), NULL, "Wrapper", NULL, 0, &mArgc, mArgv); if (xtdisplay) xt_is_initialized = TRUE; } xtclient->xtdisplay = xtdisplay; xtclient->xtvisual = xtvisual; xtclient->xtcolormap = xtcolormap; xtclient->xtdepth = xtdepth; }
void * pceXtAppContext(void * ctx) { if ( ThePceXtAppContext == NULL ) { if ( ctx != NULL ) { ThePceXtAppContext = ctx; XSetErrorHandler(x_error_handler); } else { #if defined(_REENTRANT) && defined(HAVE_XINITTHREADS) if ( XPCE_mt == TRUE ) { if ( use_x_init_threads ) XInitThreads(); } else { XPCE_mt = -1; } #else XPCE_mt = -1; #endif XtToolkitInitialize(); XSetErrorHandler(x_error_handler); if ( (ThePceXtAppContext = XtCreateApplicationContext()) == NULL ) { errorPce(TheDisplayManager(), NAME_noApplicationContext); fail; } if ( !XtSetLanguageProc(ThePceXtAppContext, NULL, NULL) ) { errorPce(TheDisplayManager(), NAME_noLocaleSupport, CtoName(setlocale(LC_ALL, NULL))); fail; } } } return ThePceXtAppContext; }
/************************************************************** * main: **************************************************************/ int main(int argc, char **argv) { Display * display; char name[132]; (void) strncpy(name, base(argv[0]), 132); /* Initialize the X Intrinsics */ XtToolkitInitialize(); /* Set up language environment for X */ XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); /* Create application context */ app_context = XtCreateApplicationContext(); XtAppSetFallbackResources(app_context, fallback_reslist); /* open up one display */ display = XtOpenDisplay(app_context, NULL, name, "XmdI18nInput", (XrmOptionDescRec *)NULL, 0, &argc, argv); if (!display) { (void) fprintf(stderr, "Unable to open display\n"); exit(0); } /* Call init functions. This creates the user interface (placed in input.c) */ if (dialog_init(&argc, argv, display) != 0) exit(1); XtAppMainLoop(app_context); return 0; /* make compiler happy */ }
int main(int argc, char ** argv) { setbuf(stdout, NULL); setbuf(stderr, NULL); Display * display = XOpenDisplay(NULL); assert(display != NULL); XSynchronize(display, True); XtAppContext context = XtCreateApplicationContext(); Widget appshell = XtVaAppInitialize(&context, "SoXtTest", NULL, 0, &argc, argv, NULL, NULL); fprintf(stderr, "appshell: %p\n", appshell); #if WANT_VISUALID int i, numvisuals; unsigned int wanted = WANT_VISUALID; XVisualInfo templ; XVisualInfo * visuals = XGetVisualInfo(display, VisualNoMask, &templ, &numvisuals); for ( i = 0; i < numvisuals; i++ ) { if ( visuals[i].visualid == wanted ) goto selected; } assert(0 && "no visual selected"); selected: Visual * visual = visuals[i].visual; int visualid = visuals[i].visualid; int depth = visuals[i].depth; Colormap colormap = 0; fprintf(stderr, "visualid: %d, depth: %d, class: %s\n", visualid, depth, visuals[i].c_class == DirectColor ? "DirectColor" : "Other"); int numcmaps; XStandardColormap * stdcolormaps = NULL; if ( XmuLookupStandardColormap(display, visuals[i].screen, visuals[i].visualid, visuals[i].depth, XA_RGB_DEFAULT_MAP, False, True) && XGetRGBColormaps(display, RootWindow(display, visuals[i].screen), &stdcolormaps, &numcmaps, XA_RGB_DEFAULT_MAP) ) { for ( int j = 0; j < numcmaps; j++ ) { if (stdcolormaps[j].visualid == visuals[i].visualid) { colormap = stdcolormaps[j].colormap; goto cont; } } colormap = XCreateColormap(display, RootWindow(display, visuals[i].screen), visuals[i].visual, AllocNone); fprintf(stderr, "standard RGB colormaps did not work with visual - created own (%ld)", colormap); } else { assert(0); } cont: fprintf(stderr, "colormap: %ld\n", colormap); #else Visual * visual = NULL; int depth = 0; Colormap colormap = 0; int snum = XDefaultScreen(display); visual = XDefaultVisual(display, snum); depth = XDefaultDepth(display, snum); colormap = XDefaultColormap(display, snum); fprintf(stderr, "visual: %p, depth: %d\n", visual, depth); fprintf(stderr, "colormap: %ld\n", colormap); #endif XtVaSetValues(appshell, XmNwidth, 100, XmNheight, 100, XmNvisual, visual, XmNcolormap, colormap, XmNdepth, depth, NULL); Widget form = XtVaCreateManagedWidget( "form", xmFormWidgetClass, appshell, NULL); Widget button = XtVaCreateManagedWidget( "button", xmPushButtonWidgetClass, form, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); Pixmap pixmap = createPixmapFromXpm(button, home_xpm); XtVaSetValues(button, XmNlabelType, XmPIXMAP, XmNlabelPixmap, pixmap, XmNlabelInsensitivePixmap, pixmap, XmNselectPixmap, pixmap, XmNselectInsensitivePixmap, pixmap, NULL); Widget list[] = { appshell, form, button, NULL }; XtSetWMColormapWindows(appshell, list, 3); XtRealizeWidget(appshell); XtAppMainLoop(context); }
/* * Two different cases : * 1. Quick print button * Parameter "wid" is a DtPrintSetupBox. * DtPrintFillSetupData fills the print_data structure. The caller must * free allocated memory locations by calling DtPrintFreeSetupData(). * The X printer connection is managed by the DtPrintSetupBox. * If printer_name is NULL then DtNprinterName is used. If DtNprinterName * differs from printer_name, then DtNprinterName is updated. * Destination and dest_info will be updated. * If a connection cannot be established then the DtPrintSetupBox will be * managed, showing an error dialog. The user can then dismiss that * dialog and use the DtPrintSetupBox to select another printer and * restart the printing operation. * 2. GUI-less operation * Parameter "wid" is NULL. * The X printer connection returned, including the print context, is managed * by the caller. * If printer_name is NULL then DtPrintFillSetupData will determine a printer * and set printer_name to this value. * Destination and dest_info will be updated. * The caller can free allocated memory by calling DtPrintFreeSetupData(). */ XtEnum DtPrintFillSetupData(Widget wid, DtPrintSetupData *print_data) { char *name = NULL, *list = NULL, *p, *q, *d, *z, *at; Display *dpy = NULL, *pdpy = NULL; XPPrinterList plist; int count; XtAppContext appc = NULL; String argv[] = { "this" }; int argc = 1; XPContext ctx; list = getenv("XPSERVERLIST"); if (wid == NULL) { /* GUI - less case (or the DtPrintSetupBox widget itself wants this). */ DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData(NULL)\n")); appc = XtCreateApplicationContext(); /* FIX ME ?? */ /* Get a printer name */ if (print_data && print_data->printer_name) name = print_data->printer_name; else if ((name = getenv("XPRINTER"))) ; else if ((name = getenv("PDPRINTER"))) ; else if ((name = getenv("LPDEST"))) ; else name = getenv("PRINTER"); if (! name) { DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData: no name\n")); /* * Destroying the application context here seems to kill test2 * XtDestroyApplicationContext(appc); */ return DtPRINT_NO_PRINTER; } DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData(name %s)\n", name)); /* Create an X printing connection */ if (print_data && print_data->print_display) dpy = print_data->print_display; /* Maybe the printer name is fully qualified */ if ((p = strchr(name, '@'))) { d = XtNewString(p+1); if ((q = strchr(d, ':')) == NULL) { d = XtRealloc(d, strlen(d)+4); strcat(d, ":0"); } /* Now d contains a host:display string, try to use it */ pdpy = XtOpenDisplay(appc, d, "", "", NULL, 0, &argc, argv); DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData opened display %p\n", pdpy)); } /* Check this display */ if (dpy) { plist = XpGetPrinterList(dpy, name, &count); if (count > 0) { pdpy = dpy; print_data->print_display = pdpy; ctx = XpCreateContext(pdpy, plist[0].name); XpSetContext(pdpy, ctx); print_data->print_context = ctx; if (print_data->printer_name) XtFree(print_data->printer_name); print_data->printer_name = XtNewString(plist[0].name); if (print_data->dest_info) XtFree(print_data->dest_info); print_data->dest_info = XtNewString(plist[0].desc); DEBUGOUT(_LtDebug(__FILE__, wid, "Got %d entries on this display\n", count)); } } /* Check the list of print servers */ if (list && ! pdpy) { DEBUGOUT(_LtDebug(__FILE__, wid, "Try XpServerlist [%s]\n", list)); z = XtMalloc(strlen(list)+5); /* Cut the list into pieces */ for (p=list; *p; p++) { while (*p && isspace(*p)) p++; if (*p == '\0') break; for (q=p, d=z; *q && !isspace(*q); q++) *(d++) = *q; *d = '\0'; /* Now z contains a piece of the list */ if (! strchr(z, ':')) strcat(z, ":0"); DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData try to open display <%s>\n", z)); pdpy = XtOpenDisplay(appc, z, "", "", NULL, 0, &argc, argv); if (! pdpy) { if (*q) p = q; else break; continue; } DEBUGOUT(_LtDebug(__FILE__, wid, "... dpy %p\n", pdpy)); plist = XpGetPrinterList(pdpy, name, &count); if (count > 0) { print_data->print_display = pdpy; ctx = XpCreateContext(pdpy, plist[0].name); XpSetContext(pdpy, ctx); print_data->print_context = ctx; if (print_data->printer_name) { XtFree(print_data->printer_name); } print_data->printer_name = XtNewString(plist[0].name); if (print_data->dest_info) { XtFree(print_data->dest_info); } print_data->dest_info = XtNewString(plist[0].desc); DEBUGOUT(_LtDebug(__FILE__, wid, "Got %d entries on display %s\n", count, z)); } if (*q) p=q; else break; } XtFree(z); } /* * Destroying the application context here seems to kill test2 * XtDestroyApplicationContext(appc); */ } else { /* wid is the DtPrintSetupBox */ DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData()\n")); appc = XtWidgetToApplicationContext(wid); if (print_data && print_data->printer_name) name = print_data->printer_name; else if (PSB_PrinterName(wid)) name = PSB_PrinterName(wid); /* This is - mostly - copied from above, there must be a better way */ /* Check the list of print servers */ if (list && ! pdpy) { DEBUGOUT(_LtDebug(__FILE__, wid, "Try XpServerlist [%s]\n", list)); z = XtMalloc(strlen(list)+5); /* Cut the list into pieces */ for (p=list; *p; p++) { while (*p && isspace(*p)) p++; if (*p == '\0') break; for (q=p, d=z; *q && !isspace(*q); q++) *(d++) = *q; *d = '\0'; /* Now z contains a piece of the list */ if (! strchr(z, ':')) strcat(z, ":0"); DEBUGOUT(_LtDebug(__FILE__, wid, "DtPrintFillSetupData try to open display <%s>\n", z)); pdpy = XtOpenDisplay(appc, z, "", "", NULL, 0, &argc, argv); if (! pdpy) { if (*q) p = q; else break; continue; } DEBUGOUT(_LtDebug(__FILE__, wid, "... dpy %p\n", pdpy)); plist = XpGetPrinterList(pdpy, name, &count); if (count > 0) { print_data->print_display = pdpy; if (print_data->print_context == (XPContext)0) { ctx = XpCreateContext(pdpy, plist[0].name); print_data->print_context = ctx; } else { ctx = print_data->print_context; } XpSetContext(pdpy, ctx); if (print_data->printer_name) { XtFree(print_data->printer_name); } print_data->printer_name = XtNewString(plist[0].name); if (print_data->dest_info) { XtFree(print_data->dest_info); } print_data->dest_info = XtNewString(plist[0].desc); DEBUGOUT(_LtDebug(__FILE__, wid, "Got %d entries on display %s\n", count, z)); } if (*q) p=q; else break; } XtFree(z); } } return DtPRINT_SUCCESS; }
int main(int argc, char **argv) { // nspluginviewer is a helper app, it shouldn't do session management at all setenv("SESSION_MANAGER", "", 1); // trap X errors kdDebug(1430) << "1 - XSetErrorHandler" << endl; XSetErrorHandler(x_errhandler); setvbuf(stderr, NULL, _IONBF, 0); kdDebug(1430) << "2 - parseCommandLine" << endl; parseCommandLine(argc, argv); #if QT_VERSION < 0x030100 // Create application kdDebug(1430) << "3 - XtToolkitInitialize" << endl; XtToolkitInitialize(); g_appcon = XtCreateApplicationContext(); Display *dpy = XtOpenDisplay(g_appcon, NULL, "nspluginviewer", "nspluginviewer", 0, 0, &argc, argv); _notifiers[0].setAutoDelete(TRUE); _notifiers[1].setAutoDelete(TRUE); _notifiers[2].setAutoDelete(TRUE); kdDebug(1430) << "4 - KXtApplication app" << endl; KLocale::setMainCatalogue("nsplugin"); KXtApplication app(dpy, argc, argv, "nspluginviewer"); #else kdDebug(1430) << "3 - create QXtEventLoop" << endl; QXtEventLoop integrator("nspluginviewer"); parseCommandLine(argc, argv); KLocale::setMainCatalogue("nsplugin"); kdDebug(1430) << "4 - create KApplication" << endl; KApplication app(argc, argv, "nspluginviewer"); GlibEvents glibevents; #endif { KConfig cfg("kcmnspluginrc", true); cfg.setGroup("Misc"); int v = KCLAMP(cfg.readNumEntry("Nice Level", 0), 0, 19); if(v > 0) { nice(v); } v = cfg.readNumEntry("Max Memory", 0); if(v > 0) { rlimit rl; memset(&rl, 0, sizeof(rl)); if(0 == getrlimit(RLIMIT_AS, &rl)) { rl.rlim_cur = kMin(v, int(rl.rlim_max)); setrlimit(RLIMIT_AS, &rl); } } } // initialize the dcop client kdDebug(1430) << "5 - app.dcopClient" << endl; DCOPClient *dcop = app.dcopClient(); if(!dcop->attach()) { KMessageBox::error(NULL, i18n("There was an error connecting to the Desktop " "communications server. Please make sure that " "the 'dcopserver' process has been started, and " "then try again."), i18n("Error Connecting to DCOP Server")); exit(1); } kdDebug(1430) << "6 - dcop->registerAs" << endl; if(g_dcopId) g_dcopId = dcop->registerAs(g_dcopId, false); else g_dcopId = dcop->registerAs("nspluginviewer"); dcop->setNotifications(true); // create dcop interface kdDebug(1430) << "7 - new NSPluginViewer" << endl; NSPluginViewer *viewer = new NSPluginViewer("viewer", 0); // start main loop #if QT_VERSION < 0x030100 kdDebug(1430) << "8 - XtAppProcessEvent" << endl; while(!g_quit) XtAppProcessEvent(g_appcon, XtIMAll); #else kdDebug(1430) << "8 - app.exec()" << endl; app.exec(); #endif // delete viewer delete viewer; }
int XtTest(int argc, char** argv) { Widget toplevel; Display* display; XtAppContext context; Widget form, label, label1, label2, button; Screen* screen; String swap; if (NULL == (swap = strrchr(argv[0], '/'))) { swap = argv[0]; } else { swap++; } context = XtCreateApplicationContext(); display = XtOpenDisplay( context, NULL, NULL, NULL, NULL, 0, &argc, argv); if (NULL == display) { return 0; } screen = XDefaultScreenOfDisplay(display); toplevel = XtVaAppCreateShell("k", "XtTest", applicationShellWidgetClass, display, XtNtitle, swap, XtNx, (screen->width /3), XtNy, (screen->height /3), NULL ); if (NULL == toplevel) { return -2; } if (3 != argc) { form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel, XmNhorizontalSpacing, 5, XmNmarginHeight, 10, XmNmarginWidth, 10, NULL ); label = XtVaCreateManagedWidget("label", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized("Usage"), XmNalignment, XmALIGNMENT_BEGINNING, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL ); label1 = XtVaCreateManagedWidget("label1", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized(swap), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL ); label2 = XtVaCreateManagedWidget("label2", xmLabelGadgetClass, form, XmNlabelString, XmStringCreateLocalized(": arg1 arg2"), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label1, XmNbottomAttachment, XmATTACH_FORM, NULL); button = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, form, XmNlabelString, XmStringCreateLocalized("Close"), XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label2, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); XtAddCallback(button, XmNactivateCallback, XtTestDC, context); XtRealizeWidget(toplevel); XtAppMainLoop(context); } XtDestroyWidget(toplevel); XtDestroyApplicationContext(context); return 0; }
int main (unsigned int argc, char **argv) { FILE *fp; /* check for existance of ARBOR_GUI_LANGUAGE, exit if absent */ if (getenv("ARBOR_GUI_LANGUAGE") == NULL) { printf("Environment variable ARBOR_GUI_LANGUAGE not set. Exiting...\n"); exit(1) ; } /* Add Xt support for i18n: locale */ XtSetLanguageProc(NULL, NULL, NULL); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, argv[0], "SysAdmin", NULL, 0, (int *) &argc, argv); if (!display) { printf("%s: can't open display, exiting...\n", argv[0]); exit (-1); } if ( argc == 2) { fp = fopen(argv[1],"r"); if ( fp == (FILE *) NULL) { printf ("\007Unable to open password file \"%s\".\n", argv[1]); exit(-1); } if (fgets(gsSybase_User,80,fp) != NULL) gsSybase_User[strlen(gsSybase_User)-1] = 0; else { printf("\007\nERROR -- Unable to read password file; exiting.") ; exit(1) ; } if (fgets(gsSybase_Pass,80,fp) != NULL) gsSybase_Pass[strlen(gsSybase_Pass)-1] = 0; else { printf("\007\nERROR -- Unable to read password file; exiting.") ; exit(1) ; } fclose(fp); if ( unlink(argv[1]) ) { printf("\007WARNING -- Unable to remove password file.\n"); } gintAutoLogin = 1; } /* Register converters, just in case you are really unlucky !! */ XmRegisterConverters(); /* String to unit type doesn't get added !! */ XtAddConverter ( XmRString, XmRUnitType, XmCvtStringToUnitType, NULL, 0 ); strcpy(gstrProcessname, "SysAdmin"); gLoginMethod1 = GUI_DSQUERY_ONLY; create_gCIloginwindow ( display, "SysAdmin", argc, argv ); XtRealizeWidget (gCIloginwindow); XmProcessTraversal(gCIpassword,XmTRAVERSE_CURRENT); if ( gintAutoLogin ) { XWithdrawWindow(display, XtWindow(gCIloginwindow), 0); XmTextSetString(gCIusername,gsSybase_User); CI_sybase_login_cb(okloginbtn, NULL, NULL); } XtAppMainLoop (app_context); return(0); }