diff --git a/src/bin/ipc.c b/src/bin/ipc.c index c9b9ee73..c848e4f1 100644 --- a/src/bin/ipc.c +++ b/src/bin/ipc.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include #include #include "ipc.h" @@ -92,6 +93,8 @@ ipc_init(void) "background", background, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, "name", name, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "theme", theme, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, "role", role, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, @@ -128,6 +131,16 @@ ipc_init(void) "hold", hold, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, "nowm", nowm, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "xterm_256color", xterm_256color, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "active_links", active_links, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "video_mute", active_links, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "cursor_blink", active_links, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance, + "visual_bell", active_links, EET_T_INT); } Eina_Bool @@ -171,6 +184,19 @@ ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst)) func_new_inst = func; } +void +ipc_instance_conn_free(void) +{ + char *hash = _ipc_hash_get(); + char *address = ecore_con_local_path_new(EINA_FALSE, + hash, + 0); + errno = 0; + unlink(address); + ERR("unlinking: '%s': %s", address, strerror(errno)); + free(address); +} + Eina_Bool ipc_instance_add(Ipc_Instance *inst) { @@ -178,7 +204,7 @@ ipc_instance_add(Ipc_Instance *inst) void *data; char *hash = _ipc_hash_get(); Ecore_Ipc_Server *ipcsrv; - + if (!hash) return EINA_FALSE; data = eet_data_descriptor_encode(new_inst_edd, inst, &size); if (!data) @@ -186,6 +212,7 @@ ipc_instance_add(Ipc_Instance *inst) free(hash); return EINA_FALSE; } + ipcsrv = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, hash, 0, NULL); if (ipcsrv) { @@ -196,6 +223,10 @@ ipc_instance_add(Ipc_Instance *inst) ecore_ipc_server_del(ipcsrv); return EINA_TRUE; } + else + { + DBG("connect failed"); + } free(data); free(hash); return EINA_FALSE; diff --git a/src/bin/ipc.h b/src/bin/ipc.h index 4ade9075..0aa4775c 100644 --- a/src/bin/ipc.h +++ b/src/bin/ipc.h @@ -7,28 +7,33 @@ typedef struct _Ipc_Instance Ipc_Instance; struct _Ipc_Instance { - const char *cmd; - const char *cd; - const char *background; - const char *name; - const char *role; - const char *title; - const char *icon_name; - const char *font; - const char *startup_id; - const char *startup_split; + char *cmd; + char *cd; + char *background; + char *name; + char *theme; + char *role; + char *title; + char *icon_name; + char *font; + char *startup_id; + char *startup_split; int x, y, w, h; - int pos; - int login_shell; - int fullscreen; - int iconic; - int borderless; - int override; - int maximized; - int hold; - int nowm; - int xterm_256color; - int active_links; + Eina_Bool pos; + Eina_Bool login_shell; + Eina_Bool fullscreen; + Eina_Bool iconic; + Eina_Bool borderless; + Eina_Bool override; + Eina_Bool maximized; + Eina_Bool hold; + Eina_Bool nowm; + Eina_Bool xterm_256color; + Eina_Bool video_mute; + Eina_Bool active_links; + Eina_Bool cursor_blink; + Eina_Bool visual_bell; + Config *config; }; void ipc_init(void); @@ -36,5 +41,6 @@ void ipc_shutdown(void); Eina_Bool ipc_serve(void); void ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst)); Eina_Bool ipc_instance_add(Ipc_Instance *inst); +void ipc_instance_conn_free(void); #endif diff --git a/src/bin/main.c b/src/bin/main.c index b50dbbe5..4aabc07b 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -26,6 +26,129 @@ Eina_Bool multisense_available = EINA_TRUE; static Config *_main_config = NULL; +static void +_set_instance_theme(Ipc_Instance *inst) +{ + char path[PATH_MAX]; + char theme_name[PATH_MAX]; + const char *theme_path = (const char *)&path; + + if (!inst->theme) + return; + + if (eina_str_has_suffix(inst->theme, ".edj")) + eina_strlcpy(theme_name, inst->theme, sizeof(theme_name)); + else + snprintf(theme_name, sizeof(theme_name), "%s.edj", inst->theme); + + if (strchr(theme_name, '/')) + eina_strlcpy(path, theme_name, sizeof(path)); + else + theme_path = theme_path_get(theme_name); + + eina_stringshare_replace(&(inst->config->theme), theme_path); + inst->config->temporary = EINA_TRUE; +} + +static void +_configure_instance(Ipc_Instance *inst) +{ + Config *config = inst->config; + + _set_instance_theme(inst); + + if (inst->background) + { + eina_stringshare_replace(&(config->background), inst->background); + config->temporary = EINA_TRUE; + } + + if (inst->font) + { + char *p = strchr(inst->font, '/'); + if (p) + { + int sz; + char *fname = alloca(p - inst->font + 1); + + strncpy(fname, inst->font, p - inst->font); + fname[p - inst->font] = '\0'; + sz = atoi(p+1); + if (sz > 0) + inst->config->font.size = sz; + eina_stringshare_replace(&(inst->config->font.name), fname); + inst->config->font.bitmap = EINA_FALSE; + } + else + { + char buf[4096], *file; + Eina_List *files; + int n = strlen(inst->font); + Eina_Bool found = EINA_FALSE; + + snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get()); + files = ecore_file_ls(buf); + EINA_LIST_FREE(files, file) + { + if (n > 0) + { + if (!strncasecmp(file, inst->font, n)) + { + n = -1; + eina_stringshare_replace(&(inst->config->font.name), file); + inst->config->font.bitmap = EINA_TRUE; + found = EINA_TRUE; + } + } + free(file); + } + if (!found) + { + ERR("font '%s' not found in %s", inst->font, buf); + } + } + config->font_set = EINA_TRUE; + config->temporary = EINA_TRUE; + } + + if (inst->login_shell) + { + inst->config->login_shell = inst->login_shell; + inst->config->temporary = EINA_TRUE; + } + inst->login_shell = inst->config->login_shell; + + if (inst->xterm_256color) + { + inst->config->xterm_256color = EINA_TRUE; + inst->config->temporary = EINA_TRUE; + } + if (inst->video_mute != 0xff) + { + config->mute = inst->video_mute; + config->temporary = EINA_TRUE; + } + if (inst->cursor_blink != 0xff) + { + config->disable_cursor_blink = !inst->cursor_blink; + config->temporary = EINA_TRUE; + } + if (inst->visual_bell != 0xff) + { + config->disable_visual_bell = !inst->visual_bell; + config->temporary = EINA_TRUE; + } + if (inst->active_links != 0xff) + { + config->active_links = !!inst->active_links; + config->active_links_email = inst->config->active_links; + config->active_links_file = inst->config->active_links; + config->active_links_url = inst->config->active_links; + config->active_links_escape = inst->config->active_links; + config->temporary = EINA_TRUE; + } +} + static void _check_multisense(void) { @@ -70,7 +193,7 @@ main_ipc_new(Ipc_Instance *inst) char buf[4096]; snprintf(buf, sizeof(buf), "DESKTOP_STARTUP_ID=%s", inst->startup_id); - putenv(buf); + putenv(strdup(buf)); } ecore_app_args_get(&pargc, &pargv); nargc = 1; @@ -93,7 +216,11 @@ main_ipc_new(Ipc_Instance *inst) if (inst->nowm) nargc += 1; if (inst->xterm_256color) nargc += 1; if (inst->active_links) nargc += 1; + if (inst->video_mute) nargc += 1; + if (inst->cursor_blink) nargc += 1; + if (inst->visual_bell) nargc += 1; if (inst->cmd) nargc += 2; + if (inst->theme) nargc += 2; nargv = calloc(nargc + 1, sizeof(char *)); if (!nargv) return; @@ -115,6 +242,11 @@ main_ipc_new(Ipc_Instance *inst) nargv[i++] = "-n"; nargv[i++] = (char *)inst->name; } + if (inst->theme) + { + nargv[i++] = "-t"; + nargv[i++] = (char *)inst->theme; + } if (inst->role) { nargv[i++] = "-r"; @@ -232,6 +364,19 @@ main_ipc_new(Ipc_Instance *inst) nargv[i++] = "-e"; nargv[i++] = (char *)inst->cmd; } + if (inst->video_mute) + { + nargv[i++] = "-m"; + } + if (inst->cursor_blink) + { + nargv[i++] = "-c"; + } + if (inst->visual_bell) + { + nargv[i++] = "-G"; + } + ecore_app_args_set(nargc, (const char **)nargv); wn = win_new(inst->name, inst->role, inst->title, inst->icon_name, @@ -247,60 +392,9 @@ main_ipc_new(Ipc_Instance *inst) win = win_evas_object_get(wn); config = win_config_get(wn); + inst->config = config; - unsetenv("DESKTOP_STARTUP_ID"); - if (inst->background) - { - eina_stringshare_replace(&(config->background), inst->background); - config->temporary = EINA_TRUE; - } - - if (inst->font) - { - if (strchr(inst->font, '/')) - { - char *fname = alloca(strlen(inst->font) + 1); - char *p; - - strcpy(fname, inst->font); - p = strrchr(fname, '/'); - if (p) - { - int sz; - - *p = 0; - p++; - sz = atoi(p); - if (sz > 0) config->font.size = sz; - eina_stringshare_replace(&(config->font.name), fname); - } - config->font.bitmap = 0; - } - else - { - char buf[4096], *file; - Eina_List *files; - int n = strlen(inst->font); - - snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get()); - files = ecore_file_ls(buf); - EINA_LIST_FREE(files, file) - { - if (n > 0) - { - if (!strncasecmp(file, inst->font, n)) - { - n = -1; - eina_stringshare_replace(&(config->font.name), file); - config->font.bitmap = 1; - } - } - free(file); - } - } - config->font_set = EINA_TRUE; - config->temporary = EINA_TRUE; - } + _configure_instance(inst); if (inst->w <= 0) inst->w = 80; if (inst->h <= 0) inst->h = 24; @@ -337,6 +431,7 @@ main_ipc_new(Ipc_Instance *inst) (ecore_evas_ecore_evas_get(evas_object_evas_get(win)), 1); ecore_app_args_set(pargc, (const char **)pargv); free(nargv); + unsetenv("DESKTOP_STARTUP_ID"); } static const char *emotion_choices[] = { @@ -468,65 +563,278 @@ _log_void(const Eina_Log_Domain *_d EINA_UNUSED, } #endif +static void +_start(Ipc_Instance *instance) +{ + Win *wn; + Evas_Object *win; + Term *term; + Config *config; + + wn = win_new(instance->name, instance->role, instance->title, + instance->icon_name, instance->config, + instance->fullscreen, instance->iconic, instance->borderless, + instance->override, instance->maximized); + // set an env so terminal apps can detect they are in terminology :) + putenv("TERMINOLOGY=1"); + + config_del(instance->config); + config = NULL; + if (!wn) + { + CRITICAL(_("Could not create window.")); + goto exit; + } + + config = win_config_get(wn); + + term = term_new(wn, config, instance->cmd, instance->login_shell, + instance->cd, + instance->w, instance->h, instance->hold, instance->title); + if (!term) + { + CRITICAL(_("Could not create terminal widget.")); + config = NULL; + goto exit; + } + + if (win_term_set(wn, term) < 0) + { + goto exit; + } + + main_trans_update(config); + main_media_update(config); + win_sizing_handle(wn); + win = win_evas_object_get(wn); + evas_object_show(win); + if (instance->startup_split) + { + unsigned int i = 0; + Eina_List *cmds_list = NULL; + Term *next = term; + + for (i = 0; i < strlen(instance->startup_split); i++) + { + char *cmd = NULL; + + if (instance->startup_split[i] == 'v') + { + cmd = cmds_list ? cmds_list->data : NULL; + split_vertically(win_evas_object_get(term_win_get(next)), + term_termio_get(next), cmd); + cmds_list = eina_list_remove_list(cmds_list, cmds_list); + } + else if (instance->startup_split[i] == 'h') + { + cmd = cmds_list ? cmds_list->data : NULL; + split_horizontally(win_evas_object_get(term_win_get(next)), + term_termio_get(next), cmd); + cmds_list = eina_list_remove_list(cmds_list, cmds_list); + } + else if (instance->startup_split[i] == '-') + next = term_next_get(next); + else + { + CRITICAL(_("invalid argument found for option -S/--split." + " See --help.")); + goto end; + } + } + if (cmds_list) + eina_list_free(cmds_list); + } + if (instance->pos) + { + int screen_w, screen_h; + + elm_win_screen_size_get(win, NULL, NULL, &screen_w, &screen_h); + if (instance->x < 0) instance->x = screen_w + instance->x; + if (instance->y < 0) instance->y = screen_h + instance->y; + evas_object_move(win, instance->x, instance->y); + } + if (instance->nowm) + ecore_evas_focus_set(ecore_evas_ecore_evas_get( + evas_object_evas_get(win)), 1); + + controls_init(); + + win_scale_wizard(win, term); + + terminology_starting_up = EINA_FALSE; + + +end: + return; +exit: + ecore_main_loop_quit(); +} + +struct Instance_Add { + Ipc_Instance *instance; + char **argv; + Eina_Bool result; + Eina_Bool timedout; + Eina_Bool done; + pthread_mutex_t lock; +}; + +static void +_instance_add_free(struct Instance_Add *add) +{ + if (!add) + return; + + pthread_mutex_destroy(&add->lock); + free(add); +} + + +static void * +_instance_sleep(void *data) +{ + struct Instance_Add *add = data; + Eina_Bool timedout = EINA_FALSE; + + sleep(2); + pthread_mutex_lock(&add->lock); + if (!add->done) + timedout = add->timedout = EINA_TRUE; + pthread_mutex_unlock(&add->lock); + if (timedout) + { + /* ok, we waited 2 seconds without any answer, + * remove the unix socket and restart terminology from scratch in a + * better state */ + ipc_instance_conn_free(); + errno = 0; + execv(add->argv[0], add->argv); + ERR("execv failed on '%s': %s", add->argv[0], strerror(errno)); + } + else + { + _instance_add_free(add); + } + + return NULL; +} + +static Eina_Bool +_instance_add_waiter(Ipc_Instance *instance, + char **argv) +{ + struct Instance_Add *add; + Eina_Bool timedout = EINA_FALSE; + Eina_Bool result = EINA_TRUE; + pthread_t thr; + + add = calloc(1, sizeof(*add)); + if (!add) + return EINA_FALSE; + + add->instance = instance; + add->argv = argv; + pthread_mutex_init(&add->lock, NULL); + + pthread_create(&thr, NULL, &_instance_sleep, add); + + /* If the unix socket is stalled, this might block */ + result = ipc_instance_add(add->instance); + pthread_mutex_lock(&add->lock); + /* Hoora, it did not block! */ + add->done = EINA_TRUE; + if (add->timedout) + { + timedout = add->timedout = EINA_TRUE; + result = EINA_FALSE; + } + pthread_mutex_unlock(&add->lock); + if (timedout) + _instance_add_free(add); + + return result; +} + +static Eina_Bool +_start_multi(Ipc_Instance *instance, + char **argv) +{ + int remote_try = 0; + do + { + if (_instance_add_waiter(instance, argv)) + { + goto exit; + } + /* Could not start a new window remotely, + * let's start our own server */ + ipc_instance_new_func_set(main_ipc_new); + if (ipc_serve()) + { + goto normal_start; + } + else + { + DBG("IPC server: failure"); + } + remote_try++; + } + while (remote_try <= 1); + +normal_start: + _start(instance); + return EINA_FALSE; + +exit: + return EINA_TRUE; +} + EAPI_MAIN int elm_main(int argc, char **argv) { - char *cmd = NULL; - char *cd = NULL; - char *theme = NULL; - char *background = NULL; char *geometry = NULL; - char *name = NULL; - char *role = NULL; - char *title = NULL; - char *icon_name = NULL; - char *font = NULL; - char *startup_split = NULL; char *video_module = NULL; - Eina_Bool login_shell = 0xff; /* unset */ - Eina_Bool video_mute = 0xff; /* unset */ - Eina_Bool cursor_blink = 0xff; /* unset */ - Eina_Bool visual_bell = 0xff; /* unset */ - Eina_Bool active_links = 0xff; /* unset */ - Eina_Bool fullscreen = EINA_FALSE; - Eina_Bool iconic = EINA_FALSE; - Eina_Bool borderless = EINA_FALSE; - Eina_Bool override = EINA_FALSE; - Eina_Bool maximized = EINA_FALSE; - Eina_Bool nowm = EINA_FALSE; Eina_Bool quit_option = EINA_FALSE; - Eina_Bool hold = EINA_FALSE; Eina_Bool single = EINA_FALSE; Eina_Bool cmd_options = EINA_FALSE; - Eina_Bool xterm_256color = EINA_FALSE; + Ipc_Instance instance = { + .login_shell = 0xff, /* unset */ + .active_links = 0xff, /* unset */ + .video_mute = 0xff, /* unset */ + .cursor_blink = 0xff, /* unset */ + .visual_bell = 0xff, /* unset */ + .startup_id = getenv("DESKTOP_STARTUP_ID"), + .w = 1, + .h = 1, + }; Ecore_Getopt_Value values[] = { ECORE_GETOPT_VALUE_BOOL(cmd_options), - ECORE_GETOPT_VALUE_STR(cd), - ECORE_GETOPT_VALUE_STR(theme), - ECORE_GETOPT_VALUE_STR(background), + ECORE_GETOPT_VALUE_STR(instance.cd), + ECORE_GETOPT_VALUE_STR(instance.theme), + ECORE_GETOPT_VALUE_STR(instance.background), ECORE_GETOPT_VALUE_STR(geometry), - ECORE_GETOPT_VALUE_STR(name), - ECORE_GETOPT_VALUE_STR(role), - ECORE_GETOPT_VALUE_STR(title), - ECORE_GETOPT_VALUE_STR(icon_name), - ECORE_GETOPT_VALUE_STR(font), - ECORE_GETOPT_VALUE_STR(startup_split), + ECORE_GETOPT_VALUE_STR(instance.name), + ECORE_GETOPT_VALUE_STR(instance.role), + ECORE_GETOPT_VALUE_STR(instance.title), + ECORE_GETOPT_VALUE_STR(instance.icon_name), + ECORE_GETOPT_VALUE_STR(instance.font), + ECORE_GETOPT_VALUE_STR(instance.startup_split), ECORE_GETOPT_VALUE_STR(video_module), - ECORE_GETOPT_VALUE_BOOL(login_shell), - ECORE_GETOPT_VALUE_BOOL(video_mute), - ECORE_GETOPT_VALUE_BOOL(cursor_blink), - ECORE_GETOPT_VALUE_BOOL(visual_bell), - ECORE_GETOPT_VALUE_BOOL(fullscreen), - ECORE_GETOPT_VALUE_BOOL(iconic), - ECORE_GETOPT_VALUE_BOOL(borderless), - ECORE_GETOPT_VALUE_BOOL(override), - ECORE_GETOPT_VALUE_BOOL(maximized), - ECORE_GETOPT_VALUE_BOOL(nowm), - ECORE_GETOPT_VALUE_BOOL(hold), + ECORE_GETOPT_VALUE_BOOL(instance.login_shell), + ECORE_GETOPT_VALUE_BOOL(instance.video_mute), + ECORE_GETOPT_VALUE_BOOL(instance.cursor_blink), + ECORE_GETOPT_VALUE_BOOL(instance.visual_bell), + ECORE_GETOPT_VALUE_BOOL(instance.fullscreen), + ECORE_GETOPT_VALUE_BOOL(instance.iconic), + ECORE_GETOPT_VALUE_BOOL(instance.borderless), + ECORE_GETOPT_VALUE_BOOL(instance.override), + ECORE_GETOPT_VALUE_BOOL(instance.maximized), + ECORE_GETOPT_VALUE_BOOL(instance.nowm), + ECORE_GETOPT_VALUE_BOOL(instance.hold), ECORE_GETOPT_VALUE_BOOL(single), - ECORE_GETOPT_VALUE_BOOL(xterm_256color), - ECORE_GETOPT_VALUE_BOOL(active_links), + ECORE_GETOPT_VALUE_BOOL(instance.xterm_256color), + ECORE_GETOPT_VALUE_BOOL(instance.active_links), ECORE_GETOPT_VALUE_BOOL(quit_option), ECORE_GETOPT_VALUE_BOOL(quit_option), @@ -535,16 +843,8 @@ elm_main(int argc, char **argv) ECORE_GETOPT_VALUE_NONE }; - Win *wn; - Term *term; - Config *config = NULL; - Evas_Object *win; int args, retval = EXIT_SUCCESS; - int remote_try = 0; - int pos_set = 0, size_set = 0; - int pos_x = 0, pos_y = 0; - int size_w = 1, size_h = 1; - Eina_List *cmds_list = NULL; + Eina_Bool size_set = EINA_FALSE; terminology_starting_up = EINA_TRUE; @@ -590,9 +890,12 @@ elm_main(int argc, char **argv) goto end; } + ecore_con_init(); + ecore_con_url_init(); + ipc_init(); - config = config_fork(_main_config); + instance.config = config_fork(_main_config); args = ecore_getopt_parse(&options, values, argc, argv); if (args < 0) @@ -606,6 +909,7 @@ elm_main(int argc, char **argv) if (cmd_options) { + Eina_List *cmds_list = NULL; int i; if (args == argc) @@ -615,11 +919,11 @@ elm_main(int argc, char **argv) goto end; } - if (startup_split) + if (instance.startup_split) { for(i = args+1; i < argc; i++) cmds_list = eina_list_append(cmds_list, argv[i]); - cmd = argv[args]; + instance.cmd = argv[args]; } else { @@ -631,86 +935,15 @@ elm_main(int argc, char **argv) eina_strbuf_append_char(strb, ' '); eina_strbuf_append(strb, argv[i]); } - cmd = eina_strbuf_string_steal(strb); + instance.cmd = eina_strbuf_string_steal(strb); eina_strbuf_free(strb); } } _check_multisense(); - if (theme) - { - char path[PATH_MAX]; - char theme_name[PATH_MAX]; - const char *theme_path = (const char *)&path; + _configure_instance(&instance); - if (eina_str_has_suffix(theme, ".edj")) - eina_strlcpy(theme_name, theme, sizeof(theme_name)); - else - snprintf(theme_name, sizeof(theme_name), "%s.edj", theme); - - if (strchr(theme_name, '/')) - eina_strlcpy(path, theme_name, sizeof(path)); - else - theme_path = theme_path_get(theme_name); - - eina_stringshare_replace(&(config->theme), theme_path); - config->temporary = EINA_TRUE; - } - - if (background) - { - eina_stringshare_replace(&(config->background), background); - config->temporary = EINA_TRUE; - } - - if (font) - { - char *p = strchr(font, '/'); - if (p) - { - int sz; - char *fname = alloca(p - font + 1); - - strncpy(fname, font, p - font); - fname[p - font] = '\0'; - sz = atoi(p+1); - if (sz > 0) config->font.size = sz; - eina_stringshare_replace(&(config->font.name), fname); - config->font.bitmap = 0; - config->font_set = 1; - } - else - { - char buf[4096], *file; - Eina_List *files; - int n = strlen(font); - Eina_Bool found = EINA_FALSE; - - snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get()); - files = ecore_file_ls(buf); - EINA_LIST_FREE(files, file) - { - if (n > 0) - { - if (!strncasecmp(file, font, n)) - { - n = -1; - eina_stringshare_replace(&(config->font.name), file); - config->font.bitmap = 1; - config->font_set = 1; - found = EINA_TRUE; - } - } - free(file); - } - if (!found) - { - ERR("font '%s' not found in %s", font, buf); - } - } - config->temporary = EINA_TRUE; - } if (video_module) { @@ -723,270 +956,109 @@ elm_main(int argc, char **argv) if (i == EINA_C_ARRAY_LENGTH(emotion_choices)) i = 0; /* ecore getopt shouldn't let this happen, but... */ - config->vidmod = i; - config->temporary = EINA_TRUE; + instance.config->vidmod = i; + instance.config->temporary = EINA_TRUE; } - if (video_mute != 0xff) - { - config->mute = video_mute; - config->temporary = EINA_TRUE; - } - if (cursor_blink != 0xff) - { - config->disable_cursor_blink = !cursor_blink; - config->temporary = EINA_TRUE; - } - if (visual_bell != 0xff) - { - config->disable_visual_bell = !visual_bell; - config->temporary = EINA_TRUE; - } - if (active_links != 0xff) - { - config->active_links = !!active_links; - config->active_links_email = config->active_links; - config->active_links_file = config->active_links; - config->active_links_url = config->active_links; - config->active_links_escape = config->active_links; - config->temporary = EINA_TRUE; - } - - if (xterm_256color) - { - config->xterm_256color = EINA_TRUE; - config->temporary = EINA_TRUE; - } if (geometry) { - if (sscanf(geometry,"%ix%i+%i+%i", &size_w, &size_h, &pos_x, &pos_y) == 4) + if (sscanf(geometry,"%ix%i+%i+%i", &instance.w, &instance.h, + &instance.x, &instance.y) == 4) { - pos_set = 1; - size_set = 1; + instance.pos = EINA_TRUE; + size_set = EINA_TRUE; } - else if (sscanf(geometry,"%ix%i-%i+%i", &size_w, &size_h, &pos_x, &pos_y) == 4) + else if (sscanf(geometry,"%ix%i-%i+%i", &instance.w, &instance.h, + &instance.x, &instance.y) == 4) { - pos_x = -pos_x; - pos_set = 1; - size_set = 1; + instance.x = -instance.x; + instance.pos = EINA_TRUE; + size_set = EINA_TRUE; } - else if (sscanf(geometry,"%ix%i-%i-%i", &size_w, &size_h, &pos_x, &pos_y) == 4) + else if (sscanf(geometry,"%ix%i-%i-%i", &instance.w, &instance.h, + &instance.x, &instance.y) == 4) { - pos_x = -pos_x; - pos_y = -pos_y; - pos_set = 1; - size_set = 1; + instance.x = -instance.x; + instance.y = -instance.y; + instance.pos = EINA_TRUE; + size_set = EINA_TRUE; } - else if (sscanf(geometry,"%ix%i+%i-%i", &size_w, &size_h, &pos_x, &pos_y) == 4) + else if (sscanf(geometry,"%ix%i+%i-%i", &instance.w, &instance.h, + &instance.x, &instance.y) == 4) { - pos_y = -pos_y; - pos_set = 1; - size_set = 1; + instance.y = -instance.y; + instance.pos = EINA_TRUE; + size_set = EINA_TRUE; } - else if (sscanf(geometry,"%ix%i", &size_w, &size_h) == 2) + else if (sscanf(geometry,"%ix%i", &instance.w, &instance.h) == 2) { - size_set = 1; + size_set = EINA_TRUE; } - else if (sscanf(geometry,"+%i+%i", &pos_x, &pos_y) == 2) + else if (sscanf(geometry,"+%i+%i", &instance.x, &instance.y) == 2) { - pos_set = 1; + instance.pos = EINA_TRUE; } - else if (sscanf(geometry,"-%i+%i", &pos_x, &pos_y) == 2) + else if (sscanf(geometry,"-%i+%i", &instance.x, &instance.y) == 2) { - pos_x = -pos_x; - pos_set = 1; + instance.x = -instance.x; + instance.pos = EINA_TRUE; } - else if (sscanf(geometry,"+%i-%i", &pos_x, &pos_y) == 2) + else if (sscanf(geometry,"+%i-%i", &instance.x, &instance.y) == 2) { - pos_y = -pos_y; - pos_set = 1; + instance.y = -instance.y; + instance.pos = EINA_TRUE; } - else if (sscanf(geometry,"-%i-%i", &pos_x, &pos_y) == 2) + else if (sscanf(geometry,"-%i-%i", &instance.x, &instance.y) == 2) { - pos_x = -pos_x; - pos_y = -pos_y; - pos_set = 1; + instance.x = -instance.x; + instance.y = -instance.y; + instance.pos = EINA_TRUE; } } if (!size_set) { - if (config->custom_geometry) + if (instance.config->custom_geometry) { - size_w = config->cg_width; - size_h = config->cg_height; + instance.w = instance.config->cg_width; + instance.h = instance.config->cg_height; } else { - size_w = 80; - size_h = 24; + instance.w = 80; + instance.h = 24; } } - if (login_shell != 0xff) - { - config->login_shell = login_shell; - config->temporary = EINA_TRUE; - } - login_shell = config->login_shell; + elm_theme_overlay_add(NULL, + config_theme_path_default_get(instance.config)); + elm_theme_overlay_add(NULL, config_theme_path_get(instance.config)); - elm_theme_overlay_add(NULL, config_theme_path_default_get(config)); - elm_theme_overlay_add(NULL, config_theme_path_get(config)); - -remote: - if ((!single) && (config->multi_instance)) + if ((!single) && (instance.config->multi_instance)) { - Ipc_Instance inst; char cwdbuf[4096]; - memset(&inst, 0, sizeof(Ipc_Instance)); - - inst.cmd = cmd; - if (cd) inst.cd = cd; - else inst.cd = getcwd(cwdbuf, sizeof(cwdbuf)); - inst.background = background; - inst.name = name; - inst.role = role; - inst.title = title; - inst.icon_name = icon_name; - inst.font = font; - inst.startup_id = getenv("DESKTOP_STARTUP_ID"); - inst.x = pos_x; - inst.y = pos_y; - inst.w = size_w; - inst.h = size_h; - inst.pos = pos_set; - inst.login_shell = login_shell; - inst.fullscreen = fullscreen; - inst.iconic = iconic; - inst.borderless = borderless; - inst.override = override; - inst.maximized = maximized; - inst.hold = hold; - inst.nowm = nowm; - inst.startup_split = startup_split; - if (ipc_instance_add(&inst)) + if (!instance.cd) + instance.cd = getcwd(cwdbuf, sizeof(cwdbuf)); + if (_start_multi(&instance, argv)) goto end; } - if ((!single) && (config->multi_instance)) + else { - ipc_instance_new_func_set(main_ipc_new); - if (!ipc_serve()) - { - if (remote_try < 1) - { - remote_try++; - goto remote; - } - } + _start(&instance); } - - wn = win_new(name, role, title, icon_name, config, - fullscreen, iconic, borderless, override, maximized); - // set an env so terminal apps can detect they are in terminology :) - putenv("TERMINOLOGY=1"); - unsetenv("DESKTOP_STARTUP_ID"); - - config_del(config); - config = NULL; - if (!wn) - { - CRITICAL(_("Could not create window.")); - retval = EXIT_FAILURE; - goto end; - } - - config = win_config_get(wn); - - term = term_new(wn, config, cmd, login_shell, cd, - size_w, size_h, hold, title); - if (!term) - { - CRITICAL(_("Could not create terminal widget.")); - config = NULL; - retval = EXIT_FAILURE; - goto end; - } - - if (win_term_set(wn, term) < 0) - { - retval = EXIT_FAILURE; - goto end; - } - - main_trans_update(config); - main_media_update(config); - win_sizing_handle(wn); - win = win_evas_object_get(wn); - evas_object_show(win); - if (startup_split) - { - unsigned int i = 0; - Term *next = term; - - for (i = 0; i < strlen(startup_split); i++) - { - if (startup_split[i] == 'v') - { - cmd = cmds_list ? cmds_list->data : NULL; - split_vertically(win_evas_object_get(term_win_get(next)), - term_termio_get(next), cmd); - cmds_list = eina_list_remove_list(cmds_list, cmds_list); - } - else if (startup_split[i] == 'h') - { - cmd = cmds_list ? cmds_list->data : NULL; - split_horizontally(win_evas_object_get(term_win_get(next)), - term_termio_get(next), cmd); - cmds_list = eina_list_remove_list(cmds_list, cmds_list); - } - else if (startup_split[i] == '-') - next = term_next_get(next); - else - { - CRITICAL(_("invalid argument found for option -S/--split." - " See --help.")); - goto end; - } - } - if (cmds_list) - eina_list_free(cmds_list); - } - if (pos_set) - { - int screen_w, screen_h; - - elm_win_screen_size_get(win, NULL, NULL, &screen_w, &screen_h); - if (pos_x < 0) pos_x = screen_w + pos_x; - if (pos_y < 0) pos_y = screen_h + pos_y; - evas_object_move(win, pos_x, pos_y); - } - if (nowm) - ecore_evas_focus_set(ecore_evas_ecore_evas_get( - evas_object_evas_get(win)), 1); - - ecore_con_init(); - ecore_con_url_init(); - - controls_init(); - - win_scale_wizard(win, term); - - terminology_starting_up = EINA_FALSE; - elm_run(); ecore_con_url_shutdown(); ecore_con_shutdown(); - config = NULL; + instance.config = NULL; end: - if (!startup_split) free(cmd); - if (config) + if (instance.config) { - config_del(config); - config = NULL; + config_del(instance.config); + instance.config = NULL; } ipc_shutdown(); diff --git a/src/bin/media.c b/src/bin/media.c index b43eadcc..28bfd2b1 100644 --- a/src/bin/media.c +++ b/src/bin/media.c @@ -1248,7 +1248,6 @@ media_add(Evas_Object *parent, const char *src, const Config *config, int mode, if (!_smart) _smart_init(); obj = evas_object_smart_add(e, _smart); sd = evas_object_smart_data_get(obj); - if (!sd) return obj; sd->src = eina_stringshare_add(src); sd->config = config; diff --git a/src/bin/win.c b/src/bin/win.c index b1556763..05fdd347 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -3324,6 +3324,7 @@ _tabs_close(Term_Container *tc, Term_Container *child) l = _tab_item_find(tabs, child); item = l->data; + tabs->tabs = eina_list_remove_list(tabs->tabs, l); next = eina_list_next(l); if (!next) @@ -3331,7 +3332,6 @@ _tabs_close(Term_Container *tc, Term_Container *child) next_item = next->data; next_child = next_item->tc; assert (next_child->type == TERM_CONTAINER_TYPE_SOLO); - tabs->tabs = eina_list_remove_list(tabs->tabs, l); assert (child->type == TERM_CONTAINER_TYPE_SOLO); solo = (Solo*)child; @@ -6060,11 +6060,11 @@ win_font_update(Term *term) void windows_free(void) { + Eina_List *l, *l_next; Win *wn; - while (wins) + EINA_LIST_FOREACH_SAFE(wins, l, l_next, wn) { - wn = eina_list_data_get(wins); win_free(wn); }