system: add app_spawn

main
Dominik Madarász 2023-09-18 09:43:28 +02:00
parent 2ec699948c
commit 5f6fbab4de
8 changed files with 32 additions and 5 deletions

View File

@ -2736,6 +2736,7 @@ int u_coefficients_sh;
void tty_attach(); void tty_attach();
void tty_detach(); void tty_detach();
const char* app_exec(const char *command); const char* app_exec(const char *command);
void app_spawn(const char *command);
int app_cores(); int app_cores();
int app_battery(); int app_battery();
const char* app_name(); const char* app_name();

View File

@ -17301,6 +17301,7 @@ API void tty_attach();
API void tty_detach(); API void tty_detach();
API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line) API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line)
API void app_spawn(const char *command);
API int app_cores(); API int app_cores();
API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present. API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present.
@ -345560,6 +345561,13 @@ const char * app_exec( const char *cmd ) {
return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output; return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output;
} }
void app_spawn( const char *cmd ) {
if( !cmd[0] ) return "0 ";
cmd = file_normalize(cmd);
system(cmd);
}
#if is(osx) #if is(osx)
#include <execinfo.h> // backtrace, backtrace_symbols #include <execinfo.h> // backtrace, backtrace_symbols
#include <dlfcn.h> // dladdr, Dl_info #include <dlfcn.h> // dladdr, Dl_info
@ -346959,6 +346967,7 @@ int ui_show(const char *panel_or_window_title, int enabled) {
} }
int ui_dims(const char *panel_or_window_title, float width, float height) { int ui_dims(const char *panel_or_window_title, float width, float height) {
nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height}); nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height});
return 0;
} }
vec2 ui_get_dims() { vec2 ui_get_dims() {
return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)}; return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)};

View File

@ -106,6 +106,13 @@ const char * app_exec( const char *cmd ) {
return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output; return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output;
} }
void app_spawn( const char *cmd ) {
if( !cmd[0] ) return "0 ";
cmd = file_normalize(cmd);
system(cmd);
}
#if is(osx) #if is(osx)
#include <execinfo.h> // backtrace, backtrace_symbols #include <execinfo.h> // backtrace, backtrace_symbols
#include <dlfcn.h> // dladdr, Dl_info #include <dlfcn.h> // dladdr, Dl_info

View File

@ -22,6 +22,7 @@ API void tty_attach();
API void tty_detach(); API void tty_detach();
API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line) API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line)
API void app_spawn(const char *command);
API int app_cores(); API int app_cores();
API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present. API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present.

View File

@ -436,6 +436,7 @@ int ui_show(const char *panel_or_window_title, int enabled) {
} }
int ui_dims(const char *panel_or_window_title, float width, float height) { int ui_dims(const char *panel_or_window_title, float width, float height) {
nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height}); nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height});
return 0;
} }
vec2 ui_get_dims() { vec2 ui_get_dims() {
return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)}; return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)};

View File

@ -16256,6 +16256,13 @@ const char * app_exec( const char *cmd ) {
return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output; return snprintf(output, 16, "%-15d", rc), buf[-1] = ' ', output;
} }
void app_spawn( const char *cmd ) {
if( !cmd[0] ) return "0 ";
cmd = file_normalize(cmd);
system(cmd);
}
#if is(osx) #if is(osx)
#include <execinfo.h> // backtrace, backtrace_symbols #include <execinfo.h> // backtrace, backtrace_symbols
#include <dlfcn.h> // dladdr, Dl_info #include <dlfcn.h> // dladdr, Dl_info
@ -17655,6 +17662,7 @@ int ui_show(const char *panel_or_window_title, int enabled) {
} }
int ui_dims(const char *panel_or_window_title, float width, float height) { int ui_dims(const char *panel_or_window_title, float width, float height) {
nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height}); nk_window_set_size(ui_ctx, panel_or_window_title, (struct nk_vec2){width, height});
return 0;
} }
vec2 ui_get_dims() { vec2 ui_get_dims() {
return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)}; return (vec2){nk_window_get_width(ui_ctx), nk_window_get_height(ui_ctx)};

View File

@ -3384,6 +3384,7 @@ API void tty_attach();
API void tty_detach(); API void tty_detach();
API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line) API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line)
API void app_spawn(const char *command);
API int app_cores(); API int app_cores();
API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present. API int app_battery(); /// return battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present.

View File

@ -44,7 +44,7 @@ void register_extensions() {
} }
void edit_asset(char *fname) { void edit_asset(char *fname) {
app_exec(va("%s %s", ifdef(win32, "start", ifdef(osx, "open", "xdg-open")), fname)); app_spawn(va("%s \"\" \"%s\"", ifdef(win32, "start", ifdef(osx, "open", "xdg-open")), fname));
} }
void load_asset(const char *fname) { void load_asset(const char *fname) {
@ -81,22 +81,21 @@ int main() {
load_editors(); load_editors();
register_extensions(); register_extensions();
#if 1 #if 0
load_asset("demos/art/shadertoys/!default.fs"); load_asset("demos/art/shadertoys/!default.fs");
load_asset("demos/art/fx/fxDithering.fs"); load_asset("demos/art/fx/fxDithering.fs");
#endif #endif
while( window_swap() && !input(KEY_ESC) ) { while( window_swap() && !input(KEY_ESC) ) {
static int wb_enabled = 1; if (ui_panel("Workbench", PANEL_OPEN)) {
if (ui_window("Workbench", &wb_enabled)) {
static const char *file; static const char *file;
static bool show_browser = 1; static bool show_browser = 1;
if( ui_browse(&file, &show_browser) ) { if( ui_browse(&file, &show_browser) ) {
load_asset(file); load_asset(file);
show_browser = 1; show_browser = 1;
} }
ui_window_end(); ui_panel_end();
} }
for (int i=0; i<array_count(assets); i++) { for (int i=0; i<array_count(assets); i++) {