This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository e16-keyedit.
View the commit online.
commit 4e3f9d5955fbf89ba074d8e79eca4c05f624ab3c
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Fri Dec 8 13:55:06 2023 +0100
Rearrange code, eliminating forward references
---
ipc.c | 353 ++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 172 insertions(+), 181 deletions(-)
diff --git a/ipc.c b/ipc.c
index e348fb0..7565483 100644
--- a/ipc.c
+++ b/ipc.c
@@ -27,83 +27,163 @@ typedef struct {
#endif
} Client;
-static Client *e_client = NULL;
-
static Display *dpy = NULL;
static Window root_win = None;
static Window comms_win = None;
static Window my_win = None;
+static Client *e_client = NULL;
static GdkWindow *gdkwin = NULL;
static GdkWindow *gdkwin2 = NULL;
static void (*msg_receive_callback)(char *msg) = NULL;
-
-static void CommsSetup(void);
-static GdkFilterReturn CommsFilter(GdkXEvent * gdk_xevent, GdkEvent * event,
- void *data);
-static Window CommsFindCommsWindow(void);
-static char *CommsGet(XEvent * ev);
-static Client *MakeClient(Window win);
-static void ListFreeClient(Client * cl);
static char in_init = 0;
static unsigned int Atom_ENL_MSG;
-int
-CommsInit(void (*msg_receive_func)(char *msg))
+static void
+CommsSetup(void)
{
- Window win;
+ char *str;
+
+ dpy = gdk_x11_get_default_xdisplay();
+
+ str = getenv("ENL_WM_ROOT");
+ root_win = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(dpy);
+
+ my_win = XCreateSimpleWindow(dpy, root_win, -10, -10, 1, 1, 0, 0, 0);
+
+ Atom_ENL_MSG = XInternAtom(dpy, "ENL_MSG", False);
+}
+
+static Window
+CommsFindCommsWindow(void)
+{
+ unsigned char *s;
+ Atom Atom_ENL_COMMS, ar;
+ unsigned long num, after;
+ int format;
+ Window win = None;
+ Window rt;
+ int dint;
+ unsigned int duint;
+
+ Atom_ENL_COMMS = XInternAtom(dpy, "ENLIGHTENMENT_COMMS", True);
+ if (Atom_ENL_COMMS == None)
+ return None;
+
+ s = NULL;
+ XGetWindowProperty(dpy, root_win, Atom_ENL_COMMS, 0, 14, False,
+ AnyPropertyType, &ar, &format, &num, &after, &s);
+ if (s)
+ {
+ sscanf((char *)s, "%*s %x", (unsigned int *)&win);
+ XFree(s);
+ }
- CommsSetup();
- comms_win = win = CommsFindCommsWindow();
if (win == None)
- return 1;
+ return None;
- e_client = MakeClient(win);
+ if (!XGetGeometry(dpy, win, &rt,
+ &dint, &dint, &duint, &duint, &duint, &duint))
+ return None;
- gdkwin = gdk_window_foreign_new(win);
- gdk_window_add_filter(gdkwin, CommsFilter, NULL);
- gdkwin2 = gdk_window_foreign_new(my_win);
- gdk_window_add_filter(gdkwin2, CommsFilter, NULL);
- gdk_window_set_events(gdkwin, GDK_STRUCTURE_MASK);
- msg_receive_callback = msg_receive_func;
+ s = NULL;
+ XGetWindowProperty(dpy, win, Atom_ENL_COMMS, 0, 14, False,
+ AnyPropertyType, &ar, &format, &num, &after, &s);
+ if (!s)
+ return None;
- return 0;
+ XFree(s);
+
+ return win;
}
-void
-CommsSend(const char *s)
+static Client *
+MakeClient(Window win)
{
- char ss[21];
- int i, j, k, len;
- XEvent ev;
- Client *cl = e_client;
+ Client *cl;
- if (!s || !cl)
+ cl = calloc(1, sizeof(Client));
+ if (!cl)
+ return cl;
+
+ cl->win = win;
+
+#if 0
+ char st[32];
+ snprintf(st, sizeof(st), "%8x", (int)win);
+ cl->name = strdup(st);
+#endif
+
+ return cl;
+}
+
+static void
+ListFreeClient(Client *cl)
+{
+ if (!cl)
return;
+ free(cl->msg);
+#if 0
+ free(cl->name);
+ free(cl->clientname);
+ free(cl->version);
+ free(cl->author);
+ free(cl->email);
+ free(cl->web);
+ free(cl->address);
+ free(cl->info);
+#endif
+ free(cl);
+}
- len = strlen(s);
+static char *
+CommsGet(XEvent *ev)
+{
+ char buf[13], *msg;
+ unsigned int win;
+ Client *cl = e_client;
- ev.xclient.type = ClientMessage;
- ev.xclient.serial = 0;
- ev.xclient.send_event = True;
- ev.xclient.window = cl->win;
- ev.xclient.message_type = Atom_ENL_MSG;
- ev.xclient.format = 8;
+ if (!cl)
+ return NULL;
- for (i = 0; i < len + 1; i += 12)
+ if (!ev)
+ return NULL;
+ if (ev->type != ClientMessage)
+ return NULL;
+ if (ev->xclient.message_type != Atom_ENL_MSG)
+ return NULL;
+
+ /* Message should start with comms_win but we don't check */
+ memcpy(buf, ev->xclient.data.b, 8);
+ buf[8] = 0;
+ sscanf(buf, "%x", &win);
+
+ memcpy(buf, ev->xclient.data.b + 8, 12);
+ buf[12] = 0;
+
+ if (cl->msg)
{
- snprintf(ss, sizeof(ss), "%8x", (int)my_win);
- for (j = 0; j < 12; j++)
- {
- ss[8 + j] = s[i + j];
- if (!s[i + j])
- j = 12;
- }
- ss[20] = 0;
- for (k = 0; k < 20; k++)
- ev.xclient.data.b[k] = ss[k];
- XSendEvent(dpy, cl->win, False, 0, &ev);
+ /* append text to end of msg */
+ cl->msg = realloc(cl->msg, strlen(cl->msg) + strlen(buf) + 1);
+ if (!cl->msg)
+ return NULL;
+ strcat(cl->msg, buf);
}
- XFlush(dpy);
+ else
+ {
+ /* new msg */
+ cl->msg = malloc(strlen(buf) + 1);
+ if (!cl->msg)
+ return NULL;
+ strcpy(cl->msg, buf);
+ }
+
+ msg = NULL;
+ if (strlen(buf) < 12)
+ {
+ msg = cl->msg;
+ cl->msg = NULL;
+ }
+ return msg;
}
static GdkFilterReturn
@@ -198,150 +278,61 @@ CommsFilter(GdkXEvent *gdk_xevent, GdkEvent *event __UNUSED__,
return GDK_FILTER_REMOVE;
}
-static void
-CommsSetup(void)
-{
- char *str;
-
- dpy = gdk_x11_get_default_xdisplay();
-
- str = getenv("ENL_WM_ROOT");
- root_win = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(dpy);
-
- my_win = XCreateSimpleWindow(dpy, root_win, -10, -10, 1, 1, 0, 0, 0);
-
- Atom_ENL_MSG = XInternAtom(dpy, "ENL_MSG", False);
-}
-
-static Window
-CommsFindCommsWindow(void)
+int
+CommsInit(void (*msg_receive_func)(char *msg))
{
- unsigned char *s;
- Atom Atom_ENL_COMMS, ar;
- unsigned long num, after;
- int format;
- Window win = None;
- Window rt;
- int dint;
- unsigned int duint;
-
- Atom_ENL_COMMS = XInternAtom(dpy, "ENLIGHTENMENT_COMMS", True);
- if (Atom_ENL_COMMS == None)
- return None;
-
- s = NULL;
- XGetWindowProperty(dpy, root_win, Atom_ENL_COMMS, 0, 14, False,
- AnyPropertyType, &ar, &format, &num, &after, &s);
- if (s)
- {
- sscanf((char *)s, "%*s %x", (unsigned int *)&win);
- XFree(s);
- }
+ Window win;
+ CommsSetup();
+ comms_win = win = CommsFindCommsWindow();
if (win == None)
- return None;
-
- if (!XGetGeometry(dpy, win, &rt,
- &dint, &dint, &duint, &duint, &duint, &duint))
- return None;
+ return 1;
- s = NULL;
- XGetWindowProperty(dpy, win, Atom_ENL_COMMS, 0, 14, False,
- AnyPropertyType, &ar, &format, &num, &after, &s);
- if (!s)
- return None;
+ e_client = MakeClient(win);
- XFree(s);
+ gdkwin = gdk_window_foreign_new(win);
+ gdk_window_add_filter(gdkwin, CommsFilter, NULL);
+ gdkwin2 = gdk_window_foreign_new(my_win);
+ gdk_window_add_filter(gdkwin2, CommsFilter, NULL);
+ gdk_window_set_events(gdkwin, GDK_STRUCTURE_MASK);
+ msg_receive_callback = msg_receive_func;
- return win;
+ return 0;
}
-static char *
-CommsGet(XEvent *ev)
+void
+CommsSend(const char *s)
{
- char buf[13], *msg;
- unsigned int win;
+ char ss[21];
+ int i, j, k, len;
+ XEvent ev;
Client *cl = e_client;
- if (!cl)
- return NULL;
-
- if (!ev)
- return NULL;
- if (ev->type != ClientMessage)
- return NULL;
- if (ev->xclient.message_type != Atom_ENL_MSG)
- return NULL;
-
- /* Message should start with comms_win but we don't check */
- memcpy(buf, ev->xclient.data.b, 8);
- buf[8] = 0;
- sscanf(buf, "%x", &win);
+ if (!s || !cl)
+ return;
- memcpy(buf, ev->xclient.data.b + 8, 12);
- buf[12] = 0;
+ len = strlen(s);
- if (cl->msg)
- {
- /* append text to end of msg */
- cl->msg = realloc(cl->msg, strlen(cl->msg) + strlen(buf) + 1);
- if (!cl->msg)
- return NULL;
- strcat(cl->msg, buf);
- }
- else
- {
- /* new msg */
- cl->msg = malloc(strlen(buf) + 1);
- if (!cl->msg)
- return NULL;
- strcpy(cl->msg, buf);
- }
+ ev.xclient.type = ClientMessage;
+ ev.xclient.serial = 0;
+ ev.xclient.send_event = True;
+ ev.xclient.window = cl->win;
+ ev.xclient.message_type = Atom_ENL_MSG;
+ ev.xclient.format = 8;
- msg = NULL;
- if (strlen(buf) < 12)
+ for (i = 0; i < len + 1; i += 12)
{
- msg = cl->msg;
- cl->msg = NULL;
+ snprintf(ss, sizeof(ss), "%8x", (int)my_win);
+ for (j = 0; j < 12; j++)
+ {
+ ss[8 + j] = s[i + j];
+ if (!s[i + j])
+ j = 12;
+ }
+ ss[20] = 0;
+ for (k = 0; k < 20; k++)
+ ev.xclient.data.b[k] = ss[k];
+ XSendEvent(dpy, cl->win, False, 0, &ev);
}
- return msg;
-}
-
-static Client *
-MakeClient(Window win)
-{
- Client *cl;
-
- cl = calloc(1, sizeof(Client));
- if (!cl)
- return cl;
-
- cl->win = win;
-
-#if 0
- char st[32];
- snprintf(st, sizeof(st), "%8x", (int)win);
- cl->name = strdup(st);
-#endif
-
- return cl;
-}
-
-static void
-ListFreeClient(Client *cl)
-{
- if (!cl)
- return;
- free(cl->msg);
-#if 0
- free(cl->name);
- free(cl->clientname);
- free(cl->version);
- free(cl->author);
- free(cl->email);
- free(cl->web);
- free(cl->address);
- free(cl->info);
-#endif
- free(cl);
+ XFlush(dpy);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.