Compare commits
6 Commits
3a0345032f
...
048c7bd36c
Author | SHA1 | Date |
---|---|---|
Kim Woelders | 048c7bd36c | |
Kim Woelders | a85954ad53 | |
Kim Woelders | 9561cc6cdc | |
Kim Woelders | 4ff99896e0 | |
Kim Woelders | d7b1d0c813 | |
Kim Woelders | 59b3428054 |
|
@ -10,7 +10,7 @@ lib_LTLIBRARIES = libepplet.la $(EPPLET_LIB_GLX)
|
||||||
|
|
||||||
include_HEADERS = epplet.h
|
include_HEADERS = epplet.h
|
||||||
|
|
||||||
libepplet_la_SOURCES = epplet.c
|
libepplet_la_SOURCES = epplet.c comms.c comms.h
|
||||||
libepplet_la_CPPFLAGS = $(AM_CPPFLAGS) $(IMLIB2_CFLAGS) $(X_CFLAGS) -D ENLIGHTENMENT_ROOT=\"$(datadir)/e16\"
|
libepplet_la_CPPFLAGS = $(AM_CPPFLAGS) $(IMLIB2_CFLAGS) $(X_CFLAGS) -D ENLIGHTENMENT_ROOT=\"$(datadir)/e16\"
|
||||||
libepplet_la_LIBADD = $(IMLIB2_LIBS) $(X_LIBS) -lXext -lX11 -lm
|
libepplet_la_LIBADD = $(IMLIB2_LIBS) $(X_LIBS) -lXext -lX11 -lm
|
||||||
libepplet_la_LDFLAGS = -version-info 4:0:1
|
libepplet_la_LDFLAGS = -version-info 4:0:1
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
#include "config.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "comms.h"
|
||||||
|
|
||||||
|
#define EXID unsigned int
|
||||||
|
|
||||||
|
static EXID comms_win = 0;
|
||||||
|
static EXID my_win = 0;
|
||||||
|
static EXID Atom_ENL_COMMS = 0;
|
||||||
|
static EXID Atom_ENL_MSG = 0;
|
||||||
|
|
||||||
|
static EXID
|
||||||
|
_CommsFindCommsWindow(void)
|
||||||
|
{
|
||||||
|
unsigned char *s;
|
||||||
|
Atom ar;
|
||||||
|
unsigned long num, after;
|
||||||
|
int format;
|
||||||
|
EXID cwin;
|
||||||
|
|
||||||
|
/* Get root window ENLIGHTENMENT_COMMS property */
|
||||||
|
cwin = 0;
|
||||||
|
s = NULL;
|
||||||
|
XGetWindowProperty(disp, root, Atom_ENL_COMMS, 0, 14, False,
|
||||||
|
AnyPropertyType, &ar, &format, &num, &after, &s);
|
||||||
|
if (!s)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
sscanf((char *)s, "%*s %x", &cwin);
|
||||||
|
XFree(s);
|
||||||
|
|
||||||
|
/* Check that cwin exists and has ENLIGHTENMENT_COMMS */
|
||||||
|
s = NULL;
|
||||||
|
XGetWindowProperty(disp, cwin, Atom_ENL_COMMS, 0, 14, False,
|
||||||
|
AnyPropertyType, &ar, &format, &num, &after, &s);
|
||||||
|
if (!s)
|
||||||
|
goto done;
|
||||||
|
XFree(s);
|
||||||
|
|
||||||
|
XSelectInput(disp, cwin, StructureNotifyMask | SubstructureNotifyMask);
|
||||||
|
|
||||||
|
done:
|
||||||
|
return cwin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CommsSetup(void)
|
||||||
|
{
|
||||||
|
if (Atom_ENL_COMMS == 0)
|
||||||
|
Atom_ENL_COMMS = XInternAtom(disp, "ENLIGHTENMENT_COMMS", False);
|
||||||
|
if (Atom_ENL_MSG == 0)
|
||||||
|
Atom_ENL_MSG = XInternAtom(disp, "ENL_MSG", False);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
comms_win = _CommsFindCommsWindow();
|
||||||
|
if (comms_win != None)
|
||||||
|
break;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!my_win)
|
||||||
|
{
|
||||||
|
my_win = XCreateWindow(disp, root, -10, -10, 1, 1, 0,
|
||||||
|
CopyFromParent, InputOnly, CopyFromParent,
|
||||||
|
0, NULL);
|
||||||
|
XSelectInput(disp, my_win,
|
||||||
|
StructureNotifyMask | SubstructureNotifyMask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CommsHandleDestroy(Window xwin)
|
||||||
|
{
|
||||||
|
if (xwin == comms_win)
|
||||||
|
comms_win = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
CommsHandlePropertyNotify(XEvent *ev)
|
||||||
|
{
|
||||||
|
if (comms_win)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ev->xproperty.atom == Atom_ENL_COMMS)
|
||||||
|
CommsSetup();
|
||||||
|
|
||||||
|
if (comms_win)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
CommsSend(const char *buf, unsigned int len)
|
||||||
|
{
|
||||||
|
char ss[21];
|
||||||
|
unsigned int i, j, k;
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
ev.xclient.type = ClientMessage;
|
||||||
|
ev.xclient.serial = 0;
|
||||||
|
ev.xclient.send_event = True;
|
||||||
|
ev.xclient.window = comms_win;
|
||||||
|
ev.xclient.message_type = Atom_ENL_MSG;
|
||||||
|
ev.xclient.format = 8;
|
||||||
|
|
||||||
|
for (i = 0; i < len + 1; i += 12)
|
||||||
|
{
|
||||||
|
snprintf(ss, sizeof(ss), "%8x", (int)my_win);
|
||||||
|
for (j = 0; j < 12; j++)
|
||||||
|
{
|
||||||
|
ss[8 + j] = buf[i + j];
|
||||||
|
if (!buf[i + j])
|
||||||
|
j = 12;
|
||||||
|
}
|
||||||
|
ss[20] = 0;
|
||||||
|
for (k = 0; k < 20; k++)
|
||||||
|
ev.xclient.data.b[k] = ss[k];
|
||||||
|
XSendEvent(disp, comms_win, False, 0, &ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Bool
|
||||||
|
ev_check(Display *d __UNUSED__, XEvent *ev, XPointer p __UNUSED__)
|
||||||
|
{
|
||||||
|
if (ev->type == ClientMessage)
|
||||||
|
{
|
||||||
|
if (ev->xclient.window == my_win)
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else if (ev->type == DestroyNotify)
|
||||||
|
{
|
||||||
|
if (ev->xdestroywindow.window == comms_win)
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
CommsWaitForMessage(void)
|
||||||
|
{
|
||||||
|
XEvent ev;
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
XIfEvent(disp, &ev, ev_check, NULL);
|
||||||
|
if (ev.type == DestroyNotify)
|
||||||
|
{
|
||||||
|
comms_win = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = CommsHandleClientMessage(&ev);
|
||||||
|
if (msg)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
CommsHandleClientMessage(XEvent *ev)
|
||||||
|
{
|
||||||
|
char s[13], s2[9], *msg = NULL;
|
||||||
|
int i;
|
||||||
|
Window win = 0;
|
||||||
|
static char *c_msg = NULL;
|
||||||
|
|
||||||
|
if (!ev)
|
||||||
|
return NULL;
|
||||||
|
if (ev->type != ClientMessage)
|
||||||
|
return NULL;
|
||||||
|
s[12] = 0;
|
||||||
|
s2[8] = 0;
|
||||||
|
msg = NULL;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
s2[i] = ev->xclient.data.b[i];
|
||||||
|
for (i = 0; i < 12; i++)
|
||||||
|
s[i] = ev->xclient.data.b[i + 8];
|
||||||
|
sscanf(s2, "%x", (int *)&win);
|
||||||
|
if (win == comms_win)
|
||||||
|
{
|
||||||
|
if (c_msg)
|
||||||
|
{
|
||||||
|
c_msg = realloc(c_msg, strlen(c_msg) + strlen(s) + 1);
|
||||||
|
if (!c_msg)
|
||||||
|
return NULL;
|
||||||
|
strcat(c_msg, s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c_msg = malloc(strlen(s) + 1);
|
||||||
|
if (!c_msg)
|
||||||
|
return NULL;
|
||||||
|
strcpy(c_msg, s);
|
||||||
|
}
|
||||||
|
if (strlen(s) < 12)
|
||||||
|
{
|
||||||
|
msg = c_msg;
|
||||||
|
c_msg = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef COMMS_H
|
||||||
|
#define COMMS_H 1
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
extern Display *disp;
|
||||||
|
extern Window root;
|
||||||
|
|
||||||
|
void CommsSetup(void);
|
||||||
|
int CommsSend(const char *buf, unsigned int len);
|
||||||
|
char *CommsWaitForMessage(void);
|
||||||
|
void CommsHandleDestroy(Window xwin);
|
||||||
|
int CommsHandlePropertyNotify(XEvent * ev);
|
||||||
|
char *CommsHandleClientMessage(XEvent * ev);
|
||||||
|
|
||||||
|
#endif /* COMMS_H */
|
243
api/epplet.c
243
api/epplet.c
|
@ -1,5 +1,4 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "epplet.h"
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
@ -13,6 +12,9 @@
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/extensions/shape.h>
|
#include <X11/extensions/shape.h>
|
||||||
|
|
||||||
|
#include "comms.h"
|
||||||
|
#include "epplet.h"
|
||||||
|
|
||||||
#define DEPTH() DefaultDepth(disp, DefaultScreen(disp))
|
#define DEPTH() DefaultDepth(disp, DefaultScreen(disp))
|
||||||
|
|
||||||
#define DEBUG_EVENTS 0
|
#define DEBUG_EVENTS 0
|
||||||
|
@ -33,6 +35,7 @@ typedef struct {
|
||||||
typedef EppWindow *Epplet_window;
|
typedef EppWindow *Epplet_window;
|
||||||
|
|
||||||
EAPI Display *disp = NULL;
|
EAPI Display *disp = NULL;
|
||||||
|
Window root = 0;
|
||||||
|
|
||||||
static int window_num = 0; /* For window list */
|
static int window_num = 0; /* For window list */
|
||||||
static Epplet_window *windows = NULL; /* List of windows to loop though */
|
static Epplet_window *windows = NULL; /* List of windows to loop though */
|
||||||
|
@ -44,9 +47,6 @@ static Epplet_window mainwin; /* Always the main epplet window */
|
||||||
|
|
||||||
static Atom wmDeleteWindow;
|
static Atom wmDeleteWindow;
|
||||||
|
|
||||||
static Window comms_win = 0;
|
|
||||||
static Window my_win = 0;
|
|
||||||
static Window root = 0;
|
|
||||||
static ETimer *q_first = NULL;
|
static ETimer *q_first = NULL;
|
||||||
static XContext xid_context = 0;
|
static XContext xid_context = 0;
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ struct _etimer {
|
||||||
ETimer *next;
|
ETimer *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ESYNC Epplet_send_ipc("nop");free(ECommsWaitForMessage());
|
#define ESYNC Epplet_send_ipc("nop");free(Epplet_wait_for_ipc());
|
||||||
|
|
||||||
/* The structures for the config file management ... */
|
/* The structures for the config file management ... */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -138,17 +138,9 @@ typedef struct {
|
||||||
|
|
||||||
static ConfigDict *config_dict = NULL;
|
static ConfigDict *config_dict = NULL;
|
||||||
|
|
||||||
static void CommsSetup(void);
|
|
||||||
static void CommsFindCommsWindow(void);
|
|
||||||
static void CommsHandleDestroy(Window win);
|
|
||||||
static int CommsHandlePropertyNotify(XEvent * ev);
|
|
||||||
static char *ECommsGet(XEvent * ev);
|
|
||||||
static char *ECommsWaitForMessage(void);
|
|
||||||
|
|
||||||
static void Epplet_handle_timer(void);
|
static void Epplet_handle_timer(void);
|
||||||
static ETimer *Epplet_get_first(void);
|
static ETimer *Epplet_get_first(void);
|
||||||
static void Epplet_handle_event(XEvent * ev);
|
static void Epplet_handle_event(XEvent * ev);
|
||||||
static Bool ev_check(Display * d, XEvent * ev, XPointer p);
|
|
||||||
static const char *win_name = NULL;
|
static const char *win_name = NULL;
|
||||||
static const char *win_version = NULL;
|
static const char *win_version = NULL;
|
||||||
static const char *win_info = NULL;
|
static const char *win_info = NULL;
|
||||||
|
@ -393,12 +385,6 @@ EXFreeGC(GC gc)
|
||||||
XFreeGC(disp, gc);
|
XFreeGC(disp, gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
Epplet_wait_for_ipc(void)
|
|
||||||
{
|
|
||||||
return ECommsWaitForMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Epplet_Init(const char *name, const char *version, const char *info,
|
Epplet_Init(const char *name, const char *version, const char *info,
|
||||||
int w, int h, int argc, char **argv, char vertical)
|
int w, int h, int argc, char **argv, char vertical)
|
||||||
|
@ -413,6 +399,7 @@ Epplet_Init(const char *name, const char *version, const char *info,
|
||||||
struct utsname ubuf;
|
struct utsname ubuf;
|
||||||
MWMHints mwm;
|
MWMHints mwm;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
#if SET_HINTS_EWM
|
#if SET_HINTS_EWM
|
||||||
Atom atom_list[8];
|
Atom atom_list[8];
|
||||||
|
@ -436,13 +423,14 @@ Epplet_Init(const char *name, const char *version, const char *info,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
root = DefaultRootWindow(disp);
|
str = getenv("ENL_WM_ROOT");
|
||||||
|
root = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(disp);
|
||||||
|
|
||||||
imlib_context_set_display(disp);
|
imlib_context_set_display(disp);
|
||||||
imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
|
imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
|
||||||
imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
|
imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
|
||||||
|
|
||||||
XSelectInput(disp, DefaultRootWindow(disp), PropertyChangeMask);
|
XSelectInput(disp, root, PropertyChangeMask);
|
||||||
|
|
||||||
/* Find the instance number for this instance and compose the name from it */
|
/* Find the instance number for this instance and compose the name from it */
|
||||||
Epplet_find_instance(name);
|
Epplet_find_instance(name);
|
||||||
|
@ -459,7 +447,7 @@ Epplet_Init(const char *name, const char *version, const char *info,
|
||||||
LeaveWindowMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask |
|
LeaveWindowMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask |
|
||||||
ExposureMask | FocusChangeMask | PropertyChangeMask |
|
ExposureMask | FocusChangeMask | PropertyChangeMask |
|
||||||
VisibilityChangeMask;
|
VisibilityChangeMask;
|
||||||
mainwin->win = XCreateWindow(disp, DefaultRootWindow(disp), 0, 0, w, h, 0,
|
mainwin->win = XCreateWindow(disp, root, 0, 0, w, h, 0,
|
||||||
CopyFromParent, InputOutput, CopyFromParent,
|
CopyFromParent, InputOutput, CopyFromParent,
|
||||||
CWOverrideRedirect | CWSaveUnder |
|
CWOverrideRedirect | CWSaveUnder |
|
||||||
CWBackingStore | CWColormap | CWBackPixel |
|
CWBackingStore | CWColormap | CWBackPixel |
|
||||||
|
@ -537,7 +525,7 @@ Epplet_Init(const char *name, const char *version, const char *info,
|
||||||
|
|
||||||
/* Check if the epplet imageclasses are there. */
|
/* Check if the epplet imageclasses are there. */
|
||||||
Epplet_send_ipc("imageclass EPPLET_BUTTON query");
|
Epplet_send_ipc("imageclass EPPLET_BUTTON query");
|
||||||
msg = ECommsWaitForMessage();
|
msg = Epplet_wait_for_ipc();
|
||||||
if (!msg || strstr(msg, "not"))
|
if (!msg || strstr(msg, "not"))
|
||||||
{
|
{
|
||||||
Epplet_dialog_ok
|
Epplet_dialog_ok
|
||||||
|
@ -597,7 +585,7 @@ Epplet_internal_create_window(int w, int h, const char *title, char vertical,
|
||||||
ButtonMotionMask | ExposureMask | FocusChangeMask |
|
ButtonMotionMask | ExposureMask | FocusChangeMask |
|
||||||
PropertyChangeMask | VisibilityChangeMask;
|
PropertyChangeMask | VisibilityChangeMask;
|
||||||
|
|
||||||
ret->win = XCreateWindow(disp, DefaultRootWindow(disp), 0, 0, w, h, 0,
|
ret->win = XCreateWindow(disp, root, 0, 0, w, h, 0,
|
||||||
CopyFromParent, InputOutput, CopyFromParent,
|
CopyFromParent, InputOutput, CopyFromParent,
|
||||||
CWOverrideRedirect | CWSaveUnder | CWBackingStore |
|
CWOverrideRedirect | CWSaveUnder | CWBackingStore |
|
||||||
CWColormap | CWBackPixel | CWBorderPixel |
|
CWColormap | CWBackPixel | CWBorderPixel |
|
||||||
|
@ -639,7 +627,7 @@ Epplet_internal_create_window(int w, int h, const char *title, char vertical,
|
||||||
|
|
||||||
/* Check if the epplet imageclasses are there. */
|
/* Check if the epplet imageclasses are there. */
|
||||||
Epplet_send_ipc("imageclass EPPLET_BUTTON query");
|
Epplet_send_ipc("imageclass EPPLET_BUTTON query");
|
||||||
msg = ECommsWaitForMessage();
|
msg = Epplet_wait_for_ipc();
|
||||||
if (!msg || strstr(msg, "not"))
|
if (!msg || strstr(msg, "not"))
|
||||||
{
|
{
|
||||||
Epplet_dialog_ok
|
Epplet_dialog_ok
|
||||||
|
@ -1018,7 +1006,7 @@ Epplet_imageclass_paste(const char *iclass, const char *state, Window ww,
|
||||||
|
|
||||||
Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass,
|
Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass,
|
||||||
(unsigned int)ww, state, w, h);
|
(unsigned int)ww, state, w, h);
|
||||||
msg = ECommsWaitForMessage();
|
msg = Epplet_wait_for_ipc();
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
sscanf(msg, "%x %x", (unsigned int *)&p, (unsigned int *)&m);
|
sscanf(msg, "%x %x", (unsigned int *)&p, (unsigned int *)&m);
|
||||||
|
@ -1043,7 +1031,7 @@ Epplet_imageclass_get_pixmaps(const char *iclass, const char *state, Pixmap *p,
|
||||||
|
|
||||||
Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass,
|
Epplet_send_ipc("imageclass %s apply_copy 0x%x %s %i %i", iclass,
|
||||||
(unsigned int)context_win->win, state, w, h);
|
(unsigned int)context_win->win, state, w, h);
|
||||||
msg = ECommsWaitForMessage();
|
msg = Epplet_wait_for_ipc();
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
sscanf(msg, "%x %x", (unsigned int *)&pp, (unsigned int *)&mm);
|
sscanf(msg, "%x %x", (unsigned int *)&pp, (unsigned int *)&mm);
|
||||||
|
@ -1087,7 +1075,7 @@ Epplet_textclass_get_size(const char *iclass, int *w, int *h, const char *txt)
|
||||||
char *msg;
|
char *msg;
|
||||||
|
|
||||||
Epplet_send_ipc("textclass %s query_size %s", iclass, txt);
|
Epplet_send_ipc("textclass %s query_size %s", iclass, txt);
|
||||||
msg = ECommsWaitForMessage();
|
msg = Epplet_wait_for_ipc();
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
sscanf(msg, "%i %i", w, h);
|
sscanf(msg, "%i %i", w, h);
|
||||||
|
@ -1242,7 +1230,7 @@ Epplet_handle_event(XEvent *ev)
|
||||||
Epplet_handle_delete_event(ev->xclient.window);
|
Epplet_handle_delete_event(ev->xclient.window);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msg = ECommsGet(ev);
|
msg = CommsHandleClientMessage(ev);
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
if (comms_func)
|
if (comms_func)
|
||||||
|
@ -1667,113 +1655,12 @@ Epplet_Loop(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
CommsSetup(void)
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
CommsFindCommsWindow();
|
|
||||||
if (comms_win != None)
|
|
||||||
break;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!my_win)
|
|
||||||
{
|
|
||||||
my_win = XCreateWindow(disp, root, -10, -10, 1, 1, 0,
|
|
||||||
CopyFromParent, InputOnly, CopyFromParent,
|
|
||||||
0, NULL);
|
|
||||||
XSelectInput(disp, my_win,
|
|
||||||
StructureNotifyMask | SubstructureNotifyMask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
CommsHandleDestroy(Window win)
|
|
||||||
{
|
|
||||||
if (win == comms_win)
|
|
||||||
comms_win = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
CommsHandlePropertyNotify(XEvent *ev)
|
|
||||||
{
|
|
||||||
Atom a = 0;
|
|
||||||
|
|
||||||
if (comms_win)
|
|
||||||
return 0;
|
|
||||||
if (!a)
|
|
||||||
a = XInternAtom(disp, "ENLIGHTENMENT_COMMS", True);
|
|
||||||
if (a == ev->xproperty.atom)
|
|
||||||
CommsSetup();
|
|
||||||
if (comms_win)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
CommsFindCommsWindow(void)
|
|
||||||
{
|
|
||||||
unsigned char *s;
|
|
||||||
Atom a, ar;
|
|
||||||
unsigned long num, after;
|
|
||||||
int format;
|
|
||||||
Window rt;
|
|
||||||
int dint;
|
|
||||||
unsigned int duint;
|
|
||||||
|
|
||||||
a = XInternAtom(disp, "ENLIGHTENMENT_COMMS", True);
|
|
||||||
if (a != None)
|
|
||||||
{
|
|
||||||
s = NULL;
|
|
||||||
XGetWindowProperty(disp, root, a, 0, 14, False, AnyPropertyType, &ar,
|
|
||||||
&format, &num, &after, &s);
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
sscanf((char *)s, "%*s %x", (unsigned int *)&comms_win);
|
|
||||||
XFree(s);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
comms_win = 0;
|
|
||||||
|
|
||||||
if (comms_win)
|
|
||||||
{
|
|
||||||
if (!XGetGeometry(disp, comms_win, &rt, &dint, &dint,
|
|
||||||
&duint, &duint, &duint, &duint))
|
|
||||||
comms_win = 0;
|
|
||||||
s = NULL;
|
|
||||||
if (comms_win)
|
|
||||||
{
|
|
||||||
XGetWindowProperty(disp, comms_win, a, 0, 14, False,
|
|
||||||
AnyPropertyType, &ar, &format, &num,
|
|
||||||
&after, &s);
|
|
||||||
if (s)
|
|
||||||
XFree(s);
|
|
||||||
else
|
|
||||||
comms_win = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (comms_win)
|
|
||||||
XSelectInput(disp, comms_win,
|
|
||||||
StructureNotifyMask | SubstructureNotifyMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Epplet_send_ipc(const char *fmt, ...)
|
Epplet_send_ipc(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static Atom a = None;
|
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char ss[21];
|
int len;
|
||||||
int i, j, k, len;
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
if (!fmt || !disp)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!a)
|
|
||||||
a = XInternAtom(disp, "ENL_MSG", False);
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
len = vsnprintf(buf, sizeof(buf), fmt, args);
|
len = vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
|
@ -1781,99 +1668,13 @@ Epplet_send_ipc(const char *fmt, ...)
|
||||||
if (len >= (int)sizeof(buf))
|
if (len >= (int)sizeof(buf))
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof(buf) - 1;
|
||||||
|
|
||||||
ev.xclient.type = ClientMessage;
|
CommsSend(buf, len);
|
||||||
ev.xclient.serial = 0;
|
|
||||||
ev.xclient.send_event = True;
|
|
||||||
ev.xclient.window = comms_win;
|
|
||||||
ev.xclient.message_type = a;
|
|
||||||
ev.xclient.format = 8;
|
|
||||||
|
|
||||||
for (i = 0; i < len + 1; i += 12)
|
|
||||||
{
|
|
||||||
snprintf(ss, sizeof(ss), "%8x", (int)my_win);
|
|
||||||
for (j = 0; j < 12; j++)
|
|
||||||
{
|
|
||||||
ss[8 + j] = buf[i + j];
|
|
||||||
if (!buf[i + j])
|
|
||||||
j = 12;
|
|
||||||
}
|
|
||||||
ss[20] = 0;
|
|
||||||
for (k = 0; k < 20; k++)
|
|
||||||
ev.xclient.data.b[k] = ss[k];
|
|
||||||
XSendEvent(disp, comms_win, False, 0, (XEvent *) & ev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Bool
|
char *
|
||||||
ev_check(Display *d __UNUSED__, XEvent *ev, XPointer p __UNUSED__)
|
Epplet_wait_for_ipc(void)
|
||||||
{
|
{
|
||||||
if (((ev->type == ClientMessage) && (ev->xclient.window == my_win)) ||
|
return CommsWaitForMessage();
|
||||||
((ev->type == DestroyNotify) &&
|
|
||||||
(ev->xdestroywindow.window == comms_win)))
|
|
||||||
return True;
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ECommsWaitForMessage(void)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
char *msg = NULL;
|
|
||||||
|
|
||||||
while ((!msg) && (comms_win))
|
|
||||||
{
|
|
||||||
XIfEvent(disp, &ev, ev_check, NULL);
|
|
||||||
if (ev.type == DestroyNotify)
|
|
||||||
comms_win = 0;
|
|
||||||
else
|
|
||||||
msg = ECommsGet(&ev);
|
|
||||||
}
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
ECommsGet(XEvent *ev)
|
|
||||||
{
|
|
||||||
char s[13], s2[9], *msg = NULL;
|
|
||||||
int i;
|
|
||||||
Window win = 0;
|
|
||||||
static char *c_msg = NULL;
|
|
||||||
|
|
||||||
if (!ev)
|
|
||||||
return NULL;
|
|
||||||
if (ev->type != ClientMessage)
|
|
||||||
return NULL;
|
|
||||||
s[12] = 0;
|
|
||||||
s2[8] = 0;
|
|
||||||
msg = NULL;
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
s2[i] = ev->xclient.data.b[i];
|
|
||||||
for (i = 0; i < 12; i++)
|
|
||||||
s[i] = ev->xclient.data.b[i + 8];
|
|
||||||
sscanf(s2, "%x", (int *)&win);
|
|
||||||
if (win == comms_win)
|
|
||||||
{
|
|
||||||
if (c_msg)
|
|
||||||
{
|
|
||||||
c_msg = realloc(c_msg, strlen(c_msg) + strlen(s) + 1);
|
|
||||||
if (!c_msg)
|
|
||||||
return NULL;
|
|
||||||
strcat(c_msg, s);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c_msg = malloc(strlen(s) + 1);
|
|
||||||
if (!c_msg)
|
|
||||||
return NULL;
|
|
||||||
strcpy(c_msg, s);
|
|
||||||
}
|
|
||||||
if (strlen(s) < 12)
|
|
||||||
{
|
|
||||||
msg = c_msg;
|
|
||||||
c_msg = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue