diff --git a/api/epplet.c b/api/epplet.c index 060b70c..b6a7907 100644 --- a/api/epplet.c +++ b/api/epplet.c @@ -129,7 +129,7 @@ struct _etimer { ETimer *next; }; -#define ESYNC ECommsSend("nop");free(ECommsWaitForMessage()); +#define ESYNC Epplet_send_ipc("nop");free(ECommsWaitForMessage()); /* The structures for the config file management ... */ typedef struct { @@ -143,7 +143,6 @@ static void CommsSetup(void); static void CommsFindCommsWindow(void); static void CommsHandleDestroy(Window win); static int CommsHandlePropertyNotify(XEvent * ev); -static void ECommsSend(const char *s); static char *ECommsGet(XEvent * ev); static char *ECommsWaitForMessage(void); @@ -396,12 +395,6 @@ EXFreeGC(GC gc) XFreeGC(disp, gc); } -void -Epplet_send_ipc(const char *s) -{ - ECommsSend(s); -} - char * Epplet_wait_for_ipc(void) { @@ -540,16 +533,13 @@ Epplet_Init(const char *name, const char *version, const char *info, win_info = info; xid_context = XUniqueContext(); CommsSetup(); - snprintf(s, sizeof(s), "set clientname %s", win_name); - ECommsSend(s); - snprintf(s, sizeof(s), "set version %s", win_version); - ECommsSend(s); - snprintf(s, sizeof(s), "set info %s", win_info); - ECommsSend(s); + Epplet_send_ipc("set clientname %s", win_name); + Epplet_send_ipc("set version %s", win_version); + Epplet_send_ipc("set info %s", win_info); ESYNC; /* Check if the epplet imageclasses are there. */ - ECommsSend("imageclass EPPLET_BUTTON query"); + Epplet_send_ipc("imageclass EPPLET_BUTTON query"); msg = ECommsWaitForMessage(); if (!msg || strstr(msg, "not")) { @@ -651,7 +641,7 @@ Epplet_internal_create_window(int w, int h, const char *title, char vertical, ESYNC; /* Check if the epplet imageclasses are there. */ - ECommsSend("imageclass EPPLET_BUTTON query"); + Epplet_send_ipc("imageclass EPPLET_BUTTON query"); msg = ECommsWaitForMessage(); if (!msg || strstr(msg, "not")) { @@ -998,19 +988,13 @@ Epplet_show(void) void Epplet_remember(void) { - char s[1024]; - - snprintf(s, sizeof(s), "wop %x snap all auto", (unsigned int)mainwin->win); - ECommsSend(s); + Epplet_send_ipc("wop %x snap all auto", (unsigned int)mainwin->win); } void Epplet_unremember(void) { - char s[1024]; - - snprintf(s, sizeof(s), "wop %x snap none", (unsigned int)mainwin->win); - ECommsSend(s); + Epplet_send_ipc("wop %x snap none", (unsigned int)mainwin->win); ESYNC; } @@ -1023,11 +1007,8 @@ Epplet_get_main_window(void) void Epplet_imageclass_apply(const char *iclass, const char *state, Window ww) { - char s[1024]; - - snprintf(s, sizeof(s), "imageclass %s apply 0x%x %s", iclass, - (unsigned int)ww, state); - ECommsSend(s); + Epplet_send_ipc("imageclass %s apply 0x%x %s", iclass, + (unsigned int)ww, state); } void @@ -1035,12 +1016,11 @@ Epplet_imageclass_paste(const char *iclass, const char *state, Window ww, int x, int y, int w, int h) { Pixmap p = 0, m = 0; - char s[1024], *msg; + char *msg; GC gc; - snprintf(s, sizeof(s), "imageclass %s apply_copy 0x%x %s %i %i", iclass, - (unsigned int)ww, state, w, h); - ECommsSend(s); + Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass, + (unsigned int)ww, state, w, h); msg = ECommsWaitForMessage(); if (msg) { @@ -1050,9 +1030,8 @@ Epplet_imageclass_paste(const char *iclass, const char *state, Window ww, XSetClipMask(disp, gc, m); XSetClipOrigin(disp, gc, x, y); XCopyArea(disp, p, context_win->win, gc, 0, 0, w, h, x, y); - snprintf(s, sizeof(s), "imageclass %s free_pixmap 0x%x", iclass, - (unsigned int)p); - ECommsSend(s); + Epplet_send_ipc("imageclass %s free_pixmap 0x%x", iclass, + (unsigned int)p); EXFreeGC(gc); } } @@ -1062,12 +1041,11 @@ Epplet_imageclass_get_pixmaps(const char *iclass, const char *state, Pixmap * p, Pixmap * m, int w, int h) { Pixmap pp = 0, mm = 0; - char s[1024], *msg; + char *msg; GC gc, mgc; - snprintf(s, sizeof(s), "imageclass %s apply_copy 0x%x %s %i %i", iclass, - (unsigned int)context_win->win, state, w, h); - ECommsSend(s); + Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass, + (unsigned int)context_win->win, state, w, h); msg = ECommsWaitForMessage(); if (msg) { @@ -1093,9 +1071,8 @@ Epplet_imageclass_get_pixmaps(const char *iclass, const char *state, Pixmap * p, XCopyArea(disp, mm, *m, mgc, 0, 0, w, h, 0, 0); EXFreeGC(mgc); } - snprintf(s, sizeof(s), "imageclass %s free_pixmap 0x%x", iclass, - (unsigned int)pp); - ECommsSend(s); + Epplet_send_ipc("imageclass %s free_pixmap 0x%x", iclass, + (unsigned int)pp); } } @@ -1103,20 +1080,16 @@ void Epplet_textclass_draw(const char *iclass, const char *state, Window ww, int x, int y, const char *txt) { - char s[1024]; - - snprintf(s, sizeof(s), "textclass %s apply 0x%x %i %i %s %s", iclass, - (unsigned int)ww, x, y, state, txt); - ECommsSend(s); + Epplet_send_ipc("textclass %s apply 0x%x %i %i %s %s", iclass, + (unsigned int)ww, x, y, state, txt); } void Epplet_textclass_get_size(const char *iclass, int *w, int *h, const char *txt) { - char s[1024], *msg = NULL; + char *msg; - snprintf(s, sizeof(s), "textclass %s query_size %s", iclass, txt); - ECommsSend(s); + Epplet_send_ipc("textclass %s query_size %s", iclass, txt); msg = ECommsWaitForMessage(); if (msg) { @@ -1786,19 +1759,28 @@ CommsFindCommsWindow(void) XSelectInput(dd, comms_win, StructureNotifyMask | SubstructureNotifyMask); } -static void -ECommsSend(const char *s) +void +Epplet_send_ipc(const char *fmt, ...) { + static Atom a = None; + va_list args; + char buf[1024]; char ss[21]; int i, j, k, len; XEvent ev; - Atom a = 0; - if (!s || !dd) + if (!fmt || !dd) return; - len = strlen(s); + if (!a) a = XInternAtom(dd, "ENL_MSG", False); + + va_start(args, fmt); + len = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + if (len >= (int)sizeof(buf)) + len = sizeof(buf) - 1; + ev.xclient.type = ClientMessage; ev.xclient.serial = 0; ev.xclient.send_event = True; @@ -1811,8 +1793,8 @@ ECommsSend(const char *s) snprintf(ss, sizeof(ss), "%8x", (int)my_win); for (j = 0; j < 12; j++) { - ss[8 + j] = s[i + j]; - if (!s[i + j]) + ss[8 + j] = buf[i + j]; + if (!buf[i + j]) j = 12; } ss[20] = 0; @@ -5377,7 +5359,7 @@ void Epplet_dialog_ok(const char *fmt, ...) { va_list args; - char buf[1000], s[1024]; + char buf[1000]; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); @@ -5389,8 +5371,7 @@ Epplet_dialog_ok(const char *fmt, ...) return; } - snprintf(s, sizeof(s), "dialog_ok %s", buf); - ECommsSend(s); + Epplet_send_ipc("dialog_ok %s", buf); } static void diff --git a/api/epplet.h.in b/api/epplet.h.in index c79556b..6b2d8f8 100644 --- a/api/epplet.h.in +++ b/api/epplet.h.in @@ -122,8 +122,8 @@ EAPI int Epplet_gadget_get_type(Epplet_gadget gad); /****************************************************************************/ /* IPC calls */ /****************************************************************************/ -/* send the string "s" to Enlightenment */ -EAPI void Epplet_send_ipc(const char *s); +/* send command to e16 */ +EAPI void Epplet_send_ipc(const char *fmt, ...); /* sit and wait for an IPc message - nothing happens whilst waiting no */ /* timers run, no events or anything else is handled. */ diff --git a/epplets/E-Slides.c b/epplets/E-Slides.c index 4d1c5ea..bed8ac5 100644 --- a/epplets/E-Slides.c +++ b/epplets/E-Slides.c @@ -218,30 +218,16 @@ set_background(int tiled, int keep_aspect) snprintf(bg_name, sizeof(bg_name), "E_SLIDES_BG_%s", filenames[CUR_PIC()]); - snprintf(buff, sizeof(buff), "background %s bg.file %s/%s", bg_name, path, - filenames[CUR_PIC()]); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.solid 0 0 0", bg_name); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.tile %d", bg_name, tiled); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.keep_aspect %d", bg_name, - keep_aspect); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.xperc %d", bg_name, - (tiled ? 0 : 1024)); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.yperc %d", bg_name, - (tiled ? 0 : 1024)); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.xjust %d", bg_name, - (tiled ? 0 : 512)); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "background %s bg.yjust %d", bg_name, - (tiled ? 0 : 512)); - Epplet_send_ipc(buff); - snprintf(buff, sizeof(buff), "use_bg %s %d", bg_name, current_desk); - Epplet_send_ipc(buff); + Epplet_send_ipc("background %s bg.file %s/%s", bg_name, path, + filenames[CUR_PIC()]); + Epplet_send_ipc("background %s bg.solid 0 0 0", bg_name); + Epplet_send_ipc("background %s bg.tile %d", bg_name, tiled); + Epplet_send_ipc("background %s bg.keep_aspect %d", bg_name, keep_aspect); + Epplet_send_ipc("background %s bg.xperc %d", bg_name, (tiled ? 0 : 1024)); + Epplet_send_ipc("background %s bg.yperc %d", bg_name, (tiled ? 0 : 1024)); + Epplet_send_ipc("background %s bg.xjust %d", bg_name, (tiled ? 0 : 512)); + Epplet_send_ipc("background %s bg.yjust %d", bg_name, (tiled ? 0 : 512)); + Epplet_send_ipc("use_bg %s %d", bg_name, current_desk); Esync(); }