int EDisplayOpen(const char *dstr, int scr) { char dbuf[256], *s; unsigned int ddpy, dscr; if (!dstr) goto do_open; Esnprintf(dbuf, sizeof(dbuf), "%s", dstr); s = strchr(dbuf, ':'); if (!s) return -1; s++; ddpy = dscr = 0; sscanf(s, "%u.%u", &ddpy, &dscr); if (scr >= 0) /* Override screen */ dscr = scr; Esnprintf(s, sizeof(dbuf) - (s - dbuf), "%u.%u", ddpy, dscr); dstr = dbuf; do_open: #ifdef USE_ECORE_X ecore_x_init(dstr); disp = ecore_x_display_get(); #else disp = XOpenDisplay(dstr); #endif return (disp) ? 0 : -1; }
static void timer_cb(void *data) { char buff[64]; double d1, d2, d3; get_load_average(&d1, &d2, &d3); one = ((d1 > 100.0) ? (100) : ((int)d1)); five = ((d2 > 100.0) ? (100) : ((int)d2)); fifteen = ((d3 > 100.0) ? (100) : ((int)d3)); Epplet_gadget_data_changed(vbar1); Epplet_gadget_data_changed(vbar2); Epplet_gadget_data_changed(vbar3); Esnprintf(buff, sizeof(buff), "%3.2f", d1); Epplet_change_label(label1, buff); Esnprintf(buff, sizeof(buff), "%3.2f", d2); Epplet_change_label(label2, buff); Esnprintf(buff, sizeof(buff), "%3.2f", d3); Epplet_change_label(label3, buff); Epplet_timer(timer_cb, NULL, 5.0, "TIMER"); return; data = NULL; }
static void parse_config(void) { char buff[1024], *s, ss[1024]; image = Epplet_query_config_def("image", "8ball.png"); Esnprintf(ss, sizeof(ss), "%s/answers.txt", Epplet_data_dir()); ans_file = Epplet_query_config_def("answers", ss); if (!parse_answers(ans_file) && !parse_answers(ans_file = ss)) { /* Couldn't find the answers. Exit. */ Esnprintf(buff, sizeof(buff), "E-Magic: Missing/invalid answers file \"%s\"", ans_file); Epplet_dialog_ok(buff); Esync(); exit(-1); } s = Epplet_query_config("delay"); if (s) { delay = atof(s); } else { Epplet_add_config("delay", "2.0"); } }
static void timer_cb(void *data) { char buff[1024]; unsigned long days, hours, mins, secs; double total_secs, delay; #ifdef HAVE_LIBGTOP glibtop_uptime uptime; glibtop_get_uptime(&uptime); secs = (unsigned long)uptime.uptime; #else FILE *fp; if (!(fp = fopen("/proc/uptime", "r"))) { D(("Failed to open /proc/uptime -- %s\n", strerror(errno))); return; } fgets(buff, sizeof(buff), fp); sscanf(buff, "%lf", &total_secs); secs = (unsigned long)total_secs; fclose(fp); #endif days = secs / 86400; secs %= 86400; hours = secs / 3600; secs %= 3600; mins = secs / 60; secs %= 60; if (secs == 0) { secs = 60; } delay = (double)secs; Esnprintf(buff, sizeof(buff), "%lu days", days); Epplet_change_label(label2, buff); Esnprintf(buff, sizeof(buff), "%lu hours", hours); Epplet_change_label(label3, buff); Esnprintf(buff, sizeof(buff), "%lu mins", mins); Epplet_change_label(label4, buff); Esync(); Epplet_timer(timer_cb, NULL, delay, "TIMER"); return; data = NULL; }
int main(int argc, char **argv) { char s[1024]; char *result = NULL; int use_count = 1; char **results = NULL; int i, num_results; Epplet_Init("E-Config", "0.1", "Enlightenment Config Test Epplet", 5, 2, argc, argv, 0); Epplet_load_config(); result = Epplet_query_config_def("USE_COUNT", "0"); use_count = atoi(result); use_count++; Esnprintf(s, sizeof(s), "%i", use_count); Epplet_modify_config("USE_COUNT", s); printf("Dump before modification:\n"); results = Epplet_query_multi_config("PARAMS", &num_results); for (i = 0; i < num_results; i++) { printf("%s\n", results[i]); } if (results) { free(results); results = NULL; } Epplet_modify_multi_config("PARAMS", argv, argc); printf("Dump after modification:\n"); results = Epplet_query_multi_config("PARAMS", &num_results); for (i = 0; i < num_results; i++) { printf("%s\n", results[i]); } if (results) free(results); Esnprintf(s, sizeof(s), "Instance %i", Epplet_get_instance()); Epplet_gadget_show(Epplet_create_label(10, 2, s, 0)); Esnprintf(s, sizeof(s), "Used %i times.", use_count); Epplet_gadget_show(Epplet_create_label(10, 14, s, 0)); Epplet_gadget_show(Epplet_create_button(NULL, NULL, 65, 2, 0, 0, "CLOSE", 0, NULL, cb_close, NULL)); Epplet_show(); Epplet_Loop(); return 0; }
static void EFonts_Init(void) { #if !TEST_TTFONT char s[4096]; Esnprintf(s, sizeof(s), "%s/ttfonts", Mode.theme.path); imlib_add_path_to_font_path(s); Esnprintf(s, sizeof(s), "%s/fonts", EDirRoot()); imlib_add_path_to_font_path(s); #endif }
/* Do something with the url. Launch it, prolly. */ static void handle_url(char *url, char *type) { char *sys = NULL; int len = 0; if (!url) return; D(("In handle_url: url -->%s<--\n", url)); if (!strcmp(type, "www")) { /* This should be close enough :) */ len = strlen(opt.www_command) + strlen(url) + 2; sys = malloc(len); Esnprintf(sys, len, opt.www_command, url); } else if (!strcmp(type, "ftp")) { /* This should be close enough :) */ len = strlen(opt.ftp_command) + strlen(url) + 2; sys = malloc(len); Esnprintf(sys, len, opt.ftp_command, url); } else if (!strcmp(type, "get")) { /* This should be close enough :) */ len = strlen(opt.get_command) + strlen(url) + 2; sys = malloc(len); Esnprintf(sys, len, opt.get_command, url); } else { /* This should be close enough :) */ len = strlen(opt.www_command) + strlen(url) + 2; sys = malloc(len); Esnprintf(sys, len, opt.www_command, url); } D(("In handle_url: About to system() -->%s<--\n", sys)); system(sys); if (!url_in_popup(url)) add_url_to_popup(url); free(sys); if (opt.save_urls) save_url(url); }
static void RunDocBrowser(void) { char buf[FILEPATH_LEN_MAX]; Esnprintf(buf, sizeof(buf), "%s/edox", EDirBin()); if (!canexec(buf)) return; Esnprintf(buf, sizeof(buf), "%s/E-docs/MAIN", EDirRoot()); if (!canread(buf)) return; Esnprintf(buf, sizeof(buf), "%s/edox %s/E-docs", EDirBin(), EDirRoot()); Espawn(buf); }
static void apply_config(void) { char buff[1024], *s; unsigned long i, j; strcpy(buff, Epplet_textbox_contents(cfg_tb_delay)); if ((delay = atof(buff)) != 0.0) { Epplet_modify_config("delay", buff); } else { delay = atof(Epplet_query_config_def("delay", "60.0")); } for (i = 0, j = 0; i < hack_cnt; i++) { s = Epplet_textbox_contents(cfg_tb_hacks[i]); if (strlen(s)) { Esnprintf(buff, sizeof(buff), "hack_%lu", j); Epplet_modify_config(buff, s); hacks[j++] = Epplet_query_config(buff); } } hack_cnt = j; if (idx >= hack_cnt) { idx = 0; } hacks = (char **)realloc(hacks, sizeof(char *) * (hack_cnt)); DEC_HACK(); change_hack(NULL); }
static ECursor * ECursorRealize(ECursor * ec) { Pixmap pmap, mask; int xh, yh; unsigned int w, h, ww, hh; char *img, msk[FILEPATH_LEN_MAX]; if (ec->file) { img = ThemeFileFind(ec->file, FILE_TYPE_CURSOR); _EFREE(ec->file); /* Ok or not - we never need file again */ if (!img) goto done; Esnprintf(msk, sizeof(msk), "%s.mask", img); pmap = 0; mask = 0; xh = 0; yh = 0; XReadBitmapFile(disp, WinGetXwin(VROOT), msk, &w, &h, &mask, &xh, &yh); XReadBitmapFile(disp, WinGetXwin(VROOT), img, &w, &h, &pmap, &xh, &yh); XQueryBestCursor(disp, WinGetXwin(VROOT), w, h, &ww, &hh); if ((w <= ww) && (h <= hh) && (pmap)) { if (xh < 0 || xh >= (int)w) xh = (int)w / 2; if (yh < 0 || yh >= (int)h) yh = (int)h / 2; ec->cursor = ECreatePixmapCursor(pmap, mask, w, h, xh, yh, ec->fg, ec->bg); } if (ec->cursor == NoXID) { Eprintf("*** Failed to create cursor \"%s\" from %s,%s\n", ec->name, img, msk); } if (pmap) EFreePixmap(pmap); if (mask) EFreePixmap(mask); Efree(img); } else { ec->cursor = (ec->native_id == 999) ? None : XCreateFontCursor(disp, ec->native_id); } done: if (ec->cursor == NoXID) { ECursorDestroy(ec); ec = NULL; } return ec; }
static void timer_cb(void *data) { char tm[64]; struct tm tim; struct tm *tim2; time_t t2; if (timezone_str && *timezone_str) { Esnprintf(tm, sizeof(tm), "TZ=%s", timezone_str); putenv(tm); } t2 = time(NULL); tim2 = localtime(&t2); if (tim2) { memcpy(&tim, tim2, sizeof(struct tm)); strftime(tm, 63, line1, &tim); Epplet_change_label(label1, tm); strftime(tm, 63, line2, &tim); Epplet_change_label(label2, tm); strftime(tm, 63, line3, &tim); Epplet_change_label(label3, tm); strftime(tm, 63, line4, &tim); Epplet_change_label(label4, tm); } Epplet_timer(timer_cb, NULL, 0.5, "TIMER"); return; data = NULL; }
static void ECheckEprog(const char *name) { char s[1024]; Esnprintf(s, sizeof(s), "%s/%s", EDirBin(), name); if (!exists(s)) { Alert(_("!!!!!!!! ERROR ERROR ERROR ERROR !!!!!!!!\n" "\n" "Enlightenment's utility executable cannot be found at:\n" "\n" "%s\n" "This is a fatal error and Enlightenment will cease to run.\n" "Please rectify this situation and ensure it is installed\n" "correctly.\n" "\n" "The reason this could be missing is due to badly created\n" "packages, someone manually deleting that program or perhaps\n" "an error in installing Enlightenment.\n"), s); EExit(1); } if (!canexec(s)) { Alert(_("!!!!!!!! ERROR ERROR ERROR ERROR !!!!!!!!\n" "\n" "Enlightenment's utility executable is not able to be executed:\n" "\n" "%s\n" "This is a fatal error and Enlightenment will cease to run.\n" "Please rectify this situation and ensure it is installed\n" "correctly.\n"), s); EExit(1); } }
void Etmp(char *s) { static unsigned int n_calls = 0; Esnprintf(s, 1024, "%s/TMP_%d_%d", EDirUser(), getpid(), n_calls++); }
static void EDirsSetup(void) { const char *home; char s[1024], *cfgdir; home = userhome(); EDirCheck(home); /* Set user config dir if not already set */ cfgdir = Mode.conf.dir; if (!cfgdir) { Esnprintf(s, sizeof(s), "%s/.e16", home); Mode.conf.dir = cfgdir = Estrdup(s); } if (exists(cfgdir)) { if (!isdir(cfgdir)) { Esnprintf(s, sizeof(s), "%s.old", cfgdir); E_mv(cfgdir, s); E_md(cfgdir); } else EDirCheck(cfgdir); } else E_md(cfgdir); if (!Mode.conf.cache_dir) Mode.conf.cache_dir = cfgdir; /* Beware if ever freed */ Esnprintf(s, sizeof(s), "%s/menus", cfgdir); Mode.firsttime = !exists(s); EDirMake(Mode.conf.dir, "themes"); EDirMake(Mode.conf.dir, "backgrounds"); EDirMake(Mode.conf.dir, "menus"); EDirMake(Mode.conf.cache_dir, "cached"); EDirMake(Mode.conf.cache_dir, "cached/cfg"); EDirMake(Mode.conf.cache_dir, "cached/bgsel"); EDirMake(Mode.conf.cache_dir, "cached/img"); EDirMake(Mode.conf.cache_dir, "cached/pager"); }
static void RunMenuGen(void) { char buf[FILEPATH_LEN_MAX]; Esnprintf(buf, sizeof(buf), "%s/scripts/e_gen_menu", EDirRoot()); execApplication(buf, EXEC_SET_LANG); }
void EventShowError(const XErrorEvent * ev) { Display *dpy = disp; char buf[64], buf1[64]; if (ev->request_code < 128) Esnprintf(buf, sizeof(buf), "%d", ev->request_code); else Esnprintf(buf, sizeof(buf), "%s.%d", EventsGetExtensionName(ev->request_code), ev->minor_code); XGetErrorDatabaseText(dpy, "XRequest", buf, "", buf1, sizeof(buf1)); XGetErrorText(dpy, ev->error_code, buf, sizeof(buf)); Eprintf("*** ERROR: xid=%#lx req=%i/%i err=%i: %s: %s\n", ev->resourceid, ev->request_code, ev->minor_code, ev->error_code, buf1, buf); }
static void RunMenuGen(void) { char buf[FILEPATH_LEN_MAX]; Esnprintf(buf, sizeof(buf), "%s/scripts/e_gen_menu", EDirRoot()); Espawn(buf); }
static void EDirMake(const char *base, const char *name) { char s[1024]; Esnprintf(s, sizeof(s), "%s/%s", base, name); if (!exists(s)) E_md(s); EDirCheck(s); }
static void load_config(void) { /* This reloads our config. */ char *home = getenv("HOME"); char buf[1024]; opt.save_urls = atoi(Epplet_query_config_def("SAVE_URLS", "1")); opt.check_url_file = atoi(Epplet_query_config_def("CHECK_URL_FILE", "1")); opt.always_show_file_urls = atoi(Epplet_query_config_def("ALWAYS_SHOW_FILE_URLS", "0")); opt.do_new_url_command = atoi(Epplet_query_config_def("RUN_COMMAND_ON_NEW_URL", "1")); /* If reloading, free the old string before assigning a new one */ if (opt.www_command) free(opt.www_command); opt.www_command = _Strdup(Epplet_query_config_def ("WWW_COMMAND", "gnome-moz-remote --newwin \"%s\" &")); if (opt.ftp_command) free(opt.ftp_command); opt.ftp_command = _Strdup(Epplet_query_config_def ("FTP_COMMAND", "gnome-moz-remote --newwin \"%s\" &")); if (opt.get_command) free(opt.get_command); opt.get_command = _Strdup(Epplet_query_config_def ("GET_COMMAND", "Eterm -O -e wget \"%s\" &")); if (opt.url_save_file) free(opt.url_save_file); Esnprintf(buf, sizeof(buf), "%s/.Urls", home); opt.url_save_file = _Strdup(Epplet_query_config_def("URL_SAVE_FILE", buf)); if (opt.url_file) free(opt.url_file); Esnprintf(buf, sizeof(buf), "%s/.te/.urls", home); opt.url_file = _Strdup(Epplet_query_config_def("URL_CHECK_FILE", buf)); if (opt.new_url_command) free(opt.new_url_command); Esnprintf(buf, sizeof(buf), "esdplay %s/wooeep.wav &", Epplet_data_dir()); opt.new_url_command = _Strdup(Epplet_query_config_def("NEW_URL_COMMAND", buf)); }
static char * AlertButtonText(int btn, char *buf, unsigned int len, const char *text) { if (!text) return NULL; Esnprintf(buf, len, "(F%d) %s", btn, text); return buf; }
static void EoptHelp(void) { unsigned int i; const EOpt *eopt; char buf[256]; printf("e16 options:\n"); for (i = 0; i < sizeof(Eopts) / sizeof(EOpt); i++) { eopt = &Eopts[i]; if (!eopt->desc) continue; if (eopt->oarg) Esnprintf(buf, sizeof(buf), "--%s <%s>", eopt->lopt, eopt->oarg); else Esnprintf(buf, sizeof(buf), "--%s", eopt->lopt); printf(" -%c %-30s\t%s\n", eopt->sopt, buf, eopt->desc); } }
/* * The user control config is called "~/.e16/e_config-$DISPLAY" * The client data appends ".clients" onto this filename and the snapshot data * appends ".snapshots". */ static void ESavePrefixSetup(void) { #define ECFG_DEFAULT "e_config" char *s, buf[1024]; if (Mode.conf.name) Esnprintf(buf, sizeof(buf), "%s/%s-%d", Mode.conf.dir, Mode.conf.name, Dpy.screen); else if (Mode.wm.window) Esnprintf(buf, sizeof(buf), "%s/%s-window", Mode.conf.dir, ECFG_DEFAULT); else Esnprintf(buf, sizeof(buf), "%s/%s-%s", Mode.conf.dir, ECFG_DEFAULT, Dpy.name); Mode.conf.prefix = Estrdup(buf); for (s = Mode.conf.prefix; (s = strchr(s, ':')); *s = '-') ; }
static void start_hack(char *hack) { char buff[1024]; Esnprintf(buff, sizeof(buff), "%s -window-id %ld", hack, Epplet_get_drawingarea_window(draw_area)); Epplet_register_child_handler(child_cb, NULL); hack_pid = Epplet_spawn_command(buff); }
const void * ModLoadSym(const char *lib, const char *sym, const char *name) { char buf[1024]; void *h; Esnprintf(buf, sizeof(buf), "%s/lib%s_%s.so", EDirLib(), lib, name); if (EDebug(1)) Eprintf("ModLoad %s\n", buf); h = dlopen(buf, RTLD_NOW | RTLD_LOCAL); if (!h) Eprintf("*** ModLoad %s: %s\n", buf, dlerror()); if (!h) return NULL; Esnprintf(buf, sizeof(buf), "%s_%s", sym, name); h = dlsym(h, buf); if (!h) Eprintf("*** ModLoad %s: %s\n", buf, dlerror()); return h; }
static void resize(int nw, int nh, int c) { char tmp_w[8], tmp_h[8]; w = nw; h = nh; save_config(); if (!c) { Epplet_unremember(); } Epplet_cleanup(); Esync(); Esnprintf(tmp_w, sizeof(tmp_w), "%d", w); Esnprintf(tmp_h, sizeof(tmp_h), "%d", h); execlp(prog_name, prog_name, "-w", tmp_w, "-h", tmp_h, (c ? "-c" : NULL), NULL); fprintf(stderr, "execlp() failed -- %s\n", strerror(errno)); }
static void save_config(void) { /* This saves our options. Numbers are printed into a buffer to make * strings. */ char buf[10]; Esnprintf(buf, sizeof(buf), "%d", opt.always_show_file_urls); Epplet_modify_config("ALWAYS_SHOW_FILE_URLS", buf); Esnprintf(buf, sizeof(buf), "%d", opt.save_urls); Epplet_modify_config("SAVE_URLS", buf); Esnprintf(buf, sizeof(buf), "%d", opt.check_url_file); Epplet_modify_config("CHECK_URL_FILE", buf); Esnprintf(buf, sizeof(buf), "%d", opt.do_new_url_command); Epplet_modify_config("RUN_COMMAND_ON_NEW_URL", buf); Epplet_modify_config("WWW_COMMAND", opt.www_command); Epplet_modify_config("FTP_COMMAND", opt.ftp_command); Epplet_modify_config("GET_COMMAND", opt.get_command); Epplet_modify_config("URL_SAVE_FILE", opt.url_save_file); Epplet_modify_config("URL_CHECK_FILE", opt.url_file); Epplet_modify_config("NEW_URL_COMMAND", opt.new_url_command); }
static void config_cb(void *data) { char buff[128]; unsigned int h, y, i; if (config_win) { return; } hacks = (char **)realloc(hacks, sizeof(char *) * (++hack_cnt)); cfg_tb_hacks = (Epplet_gadget *) malloc(sizeof(Epplet_gadget) * hack_cnt); memset(cfg_tb_hacks, 0, sizeof(Epplet_gadget) * hack_cnt); h = 70 + (hack_cnt * 41); config_win = Epplet_create_window_config(300, h, "E-Xss Configuration", ok_cb, NULL, apply_cb, NULL, cancel_cb, NULL); sprintf(buff, "%3.2f", delay); Epplet_gadget_show(Epplet_create_label (4, 4, "Delay between images (seconds):", 2)); Epplet_gadget_show(cfg_tb_delay = Epplet_create_textbox(NULL, buff, 4, 18, 292, 20, 2, NULL, NULL)); for (i = 0, y = 50; i < hack_cnt; i++) { Esnprintf(buff, sizeof(buff), "Hack #%d:", i); Epplet_gadget_show(Epplet_create_label(4, y, buff, 2)); y += 14; Epplet_gadget_show(cfg_tb_hacks[i] = Epplet_create_textbox(NULL, ((i == hack_cnt - 1) ? NULL : hacks[i]), 4, y, 292, 20, 2, NULL, NULL)); y += 27; } Epplet_window_show(config_win); Epplet_window_pop_context(); return; data = NULL; }
static void parse_config(void) { delay = atof(Epplet_query_config_def("delay", "60.0")); hacks = (char **)malloc(sizeof(char *) * (hack_cnt + 1)); for (; 1; hack_cnt++) { char *tmp; char buff[40]; Esnprintf(buff, sizeof(buff), "hack_%lu", hack_cnt); tmp = Epplet_query_config(buff); if (!tmp) { break; } hacks = (char **)realloc(hacks, sizeof(char *) * (hack_cnt + 1)); hacks[hack_cnt] = tmp; } if (hack_cnt == 0) { hack_cnt = 3; hacks = (char **)realloc(hacks, sizeof(char *) * (hack_cnt)); hacks[0] = "kaleidescope"; hacks[1] = "rorschach"; hacks[2] = "qix -solid -delay 0 -segments 100"; Epplet_add_config("hack_0", "kaleidescope"); Epplet_add_config("hack_1", "strange"); Epplet_add_config("hack_2", "qix -solid -delay 50 -segments 100"); Epplet_add_config("hack_3", "demon"); Epplet_add_config("hack_4", "bubbles"); Epplet_add_config("hack_5", "xflame"); Epplet_add_config("hack_6", "compass"); Epplet_add_config("hack_7", "drift"); Epplet_add_config("hack_8", "flow"); Epplet_add_config("hack_9", "galaxy"); Epplet_add_config("hack_10", "hypercube"); Epplet_add_config("hack_11", "ifs"); Epplet_add_config("hack_12", "kumppa -delay 20000"); Epplet_add_config("hack_13", "laser"); Epplet_add_config("hack_14", "swirl"); Epplet_add_config("hack_15", "t3d"); Epplet_add_config("hack_16", "triangle"); Epplet_add_config("hack_17", "worm"); } }
/* Scroll the string around */ static void scroll_string(void *data) { char buf[20]; static int back = 0; static int pause = 0; if (dtext.len > 19) { if (dtext.pos > (dtext.len - 19)) { dtext.pos = dtext.len - 19; back = 1; pause = 1; } else if (dtext.pos == 0) { back = 0; pause = 1; } Esnprintf(buf, sizeof(buf), "%s", dtext.str + dtext.pos); if (!back) dtext.pos += 1; else dtext.pos -= 1; Epplet_change_label(lbl_url, buf); } else Epplet_change_label(lbl_url, dtext.str); if (pause) { Epplet_timer(scroll_string, NULL, 1.0, "SCROLL_TIMER"); pause = 0; } else Epplet_timer(scroll_string, NULL, 0.3, "SCROLL_TIMER"); Esync(); return; data = NULL; }
static EFont * Efont_load(const char *file, int size) { static char ttfont_path_set = 0; char s[4096]; EFont *f; if (!ttfont_path_set) { EFonts_Init(); ttfont_path_set = 1; } Esnprintf(s, sizeof(s), "%s/%d", file, size); f = imlib_load_font(s); return f; }