@@ -344,6 +344,92 @@ void SDL_Zenity_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_Dialog
344
344
SDL_DetachThread (thread );
345
345
}
346
346
347
+ void SDL_Zenity_ShowSimpleInputDialog (SDL_DialogInputCallback callback , void * userdata , const char * title , const char * message , const char * value , SDL_Window * window )
348
+ {
349
+ SDL_Process * process = NULL ;
350
+ SDL_Environment * env = NULL ;
351
+ int status = -1 ;
352
+ size_t bytes_read = 0 ;
353
+ char * container = NULL ;
354
+ bool result = false;
355
+ const char * argv [9 ];
356
+ int argc = 0 ;
357
+
358
+ argv [argc ++ ] = "zenity" ;
359
+ argv [argc ++ ] = "--entry" ;
360
+
361
+ if (title ) {
362
+ argv [argc ++ ] = "--title" ;
363
+ argv [argc ++ ] = title ;
364
+ }
365
+
366
+ if (message ) {
367
+ argv [argc ++ ] = "--text" ;
368
+ argv [argc ++ ] = message ;
369
+ }
370
+
371
+ if (value ) {
372
+ argv [argc ++ ] = "--entry-text" ;
373
+ argv [argc ++ ] = value ;
374
+ }
375
+
376
+ argv [argc ] = NULL ;
377
+
378
+ env = SDL_CreateEnvironment (true);
379
+ if (!env ) {
380
+ goto done ;
381
+ }
382
+
383
+ /* Recent versions of Zenity have different exit codes, but picks up
384
+ different codes from the environment */
385
+ SDL_SetEnvironmentVariable (env , "ZENITY_OK" , "0" , true);
386
+ SDL_SetEnvironmentVariable (env , "ZENITY_CANCEL" , "1" , true);
387
+ SDL_SetEnvironmentVariable (env , "ZENITY_ESC" , "1" , true);
388
+ SDL_SetEnvironmentVariable (env , "ZENITY_EXTRA" , "2" , true);
389
+ SDL_SetEnvironmentVariable (env , "ZENITY_ERROR" , "2" , true);
390
+ SDL_SetEnvironmentVariable (env , "ZENITY_TIMEOUT" , "2" , true);
391
+
392
+ SDL_PropertiesID props = SDL_CreateProperties ();
393
+ SDL_SetPointerProperty (props , SDL_PROP_PROCESS_CREATE_ARGS_POINTER , argv );
394
+ SDL_SetPointerProperty (props , SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER , env );
395
+ SDL_SetNumberProperty (props , SDL_PROP_PROCESS_CREATE_STDIN_NUMBER , SDL_PROCESS_STDIO_NULL );
396
+ SDL_SetNumberProperty (props , SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER , SDL_PROCESS_STDIO_APP );
397
+ SDL_SetNumberProperty (props , SDL_PROP_PROCESS_CREATE_STDERR_NUMBER , SDL_PROCESS_STDIO_NULL );
398
+ process = SDL_CreateProcessWithProperties (props );
399
+ SDL_DestroyProperties (props );
400
+ if (!process ) {
401
+ goto done ;
402
+ }
403
+
404
+ container = SDL_ReadProcess (process , & bytes_read , & status );
405
+ if (!container ) {
406
+ goto done ;
407
+ }
408
+
409
+ // Strings returned by Zenity finish with '\n'; swap that with a '\0'
410
+ container [bytes_read - 1 ] = '\0' ;
411
+
412
+ if (status == 0 ) {
413
+ callback (userdata , container );
414
+ } else if (status == 1 ) {
415
+ callback (userdata , "" );
416
+ } else {
417
+ SDL_SetError ("Could not run zenity: exit code %d" , status );
418
+ callback (userdata , NULL );
419
+ }
420
+
421
+ result = true;
422
+
423
+ done :
424
+ SDL_free (container );
425
+ SDL_DestroyEnvironment (env );
426
+ SDL_DestroyProcess (process );
427
+
428
+ if (!result ) {
429
+ callback (userdata , NULL );
430
+ }
431
+ }
432
+
347
433
bool SDL_Zenity_detect (void )
348
434
{
349
435
const char * args [] = {
0 commit comments