summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorTom Gilbert <gilbertt@users.sourceforge.net>2000-10-20 10:48:21 +0000
committerTom Gilbert <gilbertt@users.sourceforge.net>2000-10-20 10:48:21 +0000
commit8685930a75460d8493f47a3270a273c63ead3ea5 (patch)
treecada6266a0dc4688e3b3b4687d908390630087ba /legacy
parentf984e4ab77a347ecbcabfabd74c24655765c7a59 (diff)
Initial event abstraction for e17. More work needed.
SVN revision: 3663
Diffstat (limited to '')
-rw-r--r--legacy/ecore/.cvsignore29
-rw-r--r--legacy/ecore/AUTHORS2
-rw-r--r--legacy/ecore/COPYING20
-rw-r--r--legacy/ecore/ChangeLog0
-rw-r--r--legacy/ecore/INSTALL0
-rw-r--r--legacy/ecore/Makefile.am31
-rw-r--r--legacy/ecore/NEWS0
-rw-r--r--legacy/ecore/README0
-rw-r--r--legacy/ecore/acconfig.h3
-rwxr-xr-xlegacy/ecore/autogen.sh148
-rw-r--r--legacy/ecore/configure.in61
-rw-r--r--legacy/ecore/src/.cvsignore29
-rw-r--r--legacy/ecore/src/Makefile.am19
-rw-r--r--legacy/ecore/src/e_ev_filter.c128
-rw-r--r--legacy/ecore/src/e_ev_filter.h15
-rw-r--r--legacy/ecore/src/e_ev_signal.c323
-rw-r--r--legacy/ecore/src/e_ev_signal.h5
-rw-r--r--legacy/ecore/src/e_ev_x.c1029
-rw-r--r--legacy/ecore/src/e_ev_x.h5
-rw-r--r--legacy/ecore/src/e_events.c404
-rw-r--r--legacy/ecore/src/e_events.h430
-rw-r--r--legacy/ecore/src/e_mem.c1
-rw-r--r--legacy/ecore/src/e_mem.h60
-rw-r--r--legacy/ecore/src/e_str.c151
-rw-r--r--legacy/ecore/src/e_str.h18
-rw-r--r--legacy/ecore/src/e_util.c164
-rw-r--r--legacy/ecore/src/e_util.h56
-rw-r--r--legacy/ecore/src/e_x.c2306
-rw-r--r--legacy/ecore/src/e_x.h230
29 files changed, 5667 insertions, 0 deletions
diff --git a/legacy/ecore/.cvsignore b/legacy/ecore/.cvsignore
new file mode 100644
index 0000000000..dd4706c923
--- /dev/null
+++ b/legacy/ecore/.cvsignore
@@ -0,0 +1,29 @@
1*.lo
2*.la
3.deps
4.libs
5Makefile
6Makefile.in
7aclocal.m4
8confdefs.h
9config.cache
10config.guess
11config.h
12config.h.in
13config.log
14config.status
15config.sub
16configure
17install-sh
18libtool
19ltconfig
20ltmain.sh
21missing
22mkinstalldirs
23stamp-h
24stamp-h.in
25*.tar.gz
26macros
27*~
28*.spec
29.icons
diff --git a/legacy/ecore/AUTHORS b/legacy/ecore/AUTHORS
new file mode 100644
index 0000000000..d3fe787a6d
--- /dev/null
+++ b/legacy/ecore/AUTHORS
@@ -0,0 +1,2 @@
1The Rasterman <raster@rasterman.com>
2Tom Gilbert <tom@linuxbrit.co.uk>
diff --git a/legacy/ecore/COPYING b/legacy/ecore/COPYING
new file mode 100644
index 0000000000..dee3047c34
--- /dev/null
+++ b/legacy/ecore/COPYING
@@ -0,0 +1,20 @@
1Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS)
2
3Permission is hereby granted, free of charge, to any person obtaining a copy
4of this software and associated documentation files (the "Software"), to
5deal in the Software without restriction, including without limitation the
6rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7sell copies of the Software, and to permit persons to whom the Software is
8furnished to do so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in
11all copies of the Software, its documentation and marketing & publicity
12materials, and acknowledgment shall be given in the documentation, materials
13and software packages that this Software was used.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/legacy/ecore/ChangeLog b/legacy/ecore/ChangeLog
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/ecore/ChangeLog
diff --git a/legacy/ecore/INSTALL b/legacy/ecore/INSTALL
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/ecore/INSTALL
diff --git a/legacy/ecore/Makefile.am b/legacy/ecore/Makefile.am
new file mode 100644
index 0000000000..d471750b91
--- /dev/null
+++ b/legacy/ecore/Makefile.am
@@ -0,0 +1,31 @@
1## Process this file with automake to produce Makefile.in
2
3SUBDIRS = src
4
5MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \
6 config.h.in config.sub configure install-sh \
7 ltconfig ltmain.sh missing mkinstalldirs \
8 stamp-h.in
9
10install-data-local:
11 @$(NORMAL_INSTALL)
12 if test -d $(srcdir)/data; then \
13 $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \
14 for file in $(srcdir)/data/*; do \
15 if test -f $$file; then \
16 $(INSTALL_DATA) $$file $(DESTDIR)$(pkgdatadir)/; \
17 fi \
18 done \
19 fi
20
21dist-hook:
22 if test -d data; then \
23 mkdir $(distdir)/data; \
24 for file in data/*; do \
25 if test -f $$file; then \
26 cp -p $$file $(distdir)/data; \
27 fi \
28 done \
29 fi
30
31EXTRA_DIST = README AUTHORS COPYING
diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/ecore/NEWS
diff --git a/legacy/ecore/README b/legacy/ecore/README
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/legacy/ecore/README
diff --git a/legacy/ecore/acconfig.h b/legacy/ecore/acconfig.h
new file mode 100644
index 0000000000..b579d502e4
--- /dev/null
+++ b/legacy/ecore/acconfig.h
@@ -0,0 +1,3 @@
1#undef PACKAGE_LOCALE_DIR
2#undef PACKAGE_DATA_DIR
3#undef PACKAGE_SOURCE_DIR
diff --git a/legacy/ecore/autogen.sh b/legacy/ecore/autogen.sh
new file mode 100755
index 0000000000..9370100750
--- /dev/null
+++ b/legacy/ecore/autogen.sh
@@ -0,0 +1,148 @@
1#!/bin/sh
2# Run this to generate all the initial makefiles, etc.
3
4srcdir=`dirname $0`
5PKG_NAME="libecore"
6
7DIE=0
8
9(autoconf --version) < /dev/null > /dev/null 2>&1 || {
10 echo
11 echo "**Error**: You must have \`autoconf' installed to."
12 echo "Download the appropriate package for your distribution,"
13 echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
14 DIE=1
15}
16
17(grep "^AM_PROG_LIBTOOL" $srcdir/configure.in >/dev/null) && {
18 (libtool --version) < /dev/null > /dev/null 2>&1 || {
19 echo
20 echo "**Error**: You must have \`libtool' installed."
21 echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz"
22 echo "(or a newer version if it is available)"
23 DIE=1
24 }
25}
26
27grep "^AM_GNU_GETTEXT" $srcdir/configure.in >/dev/null && {
28 grep "sed.*POTFILES" $srcdir/configure.in >/dev/null || \
29 (gettext --version) < /dev/null > /dev/null 2>&1 || {
30 echo
31 echo "**Error**: You must have \`gettext' installed."
32 echo "Get ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz"
33 echo "(or a newer version if it is available)"
34 DIE=1
35 }
36}
37
38grep "^AM_GNOME_GETTEXT" $srcdir/configure.in >/dev/null && {
39 grep "sed.*POTFILES" $srcdir/configure.in >/dev/null || \
40 (gettext --version) < /dev/null > /dev/null 2>&1 || {
41 echo
42 echo "**Error**: You must have \`gettext' installed."
43 echo "Get ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz"
44 echo "(or a newer version if it is available)"
45 DIE=1
46 }
47}
48
49(automake --version) < /dev/null > /dev/null 2>&1 || {
50 echo
51 echo "**Error**: You must have \`automake' installed."
52 echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz"
53 echo "(or a newer version if it is available)"
54 DIE=1
55 NO_AUTOMAKE=yes
56}
57
58
59# if no automake, don't bother testing for aclocal
60test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
61 echo
62 echo "**Error**: Missing \`aclocal'. The version of \`automake'"
63 echo "installed doesn't appear recent enough."
64 echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz"
65 echo "(or a newer version if it is available)"
66 DIE=1
67}
68
69if test "$DIE" -eq 1; then
70 exit 1
71fi
72
73if test -z "$*"; then
74 echo "**Warning**: I am going to run \`configure' with no arguments."
75 echo "If you wish to pass any to it, please specify them on the"
76 echo \`$0\'" command line."
77 echo
78fi
79
80case $CC in
81xlc )
82 am_opt=--include-deps;;
83esac
84
85for coin in `find $srcdir -name configure.in -print`
86do
87 dr=`dirname $coin`
88 if test -f $dr/NO-AUTO-GEN; then
89 echo skipping $dr -- flagged as no auto-gen
90 else
91 echo processing $dr
92 macrodirs=`sed -n -e 's,AM_ACLOCAL_INCLUDE(\(.*\)),\1,gp' < $coin`
93 ( cd $dr
94 aclocalinclude="$ACLOCAL_FLAGS"
95 for k in $macrodirs; do
96 if test -d $k; then
97 aclocalinclude="$aclocalinclude -I $k"
98 ##else
99 ## echo "**Warning**: No such directory \`$k'. Ignored."
100 fi
101 done
102 if grep "^AM_GNU_GETTEXT" configure.in >/dev/null; then
103 if grep "sed.*POTFILES" configure.in >/dev/null; then
104 : do nothing -- we still have an old unmodified configure.in
105 else
106 echo "Creating $dr/aclocal.m4 ..."
107 test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
108 echo "Running gettextize... Ignore non-fatal messages."
109 echo "no" | gettextize --force --copy
110 echo "Making $dr/aclocal.m4 writable ..."
111 test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
112 fi
113 fi
114 if grep "^AM_GNOME_GETTEXT" configure.in >/dev/null; then
115 echo "Creating $dr/aclocal.m4 ..."
116 test -r $dr/aclocal.m4 || touch $dr/aclocal.m4
117 echo "Running gettextize... Ignore non-fatal messages."
118 echo "no" | gettextize --force --copy
119 echo "Making $dr/aclocal.m4 writable ..."
120 test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4
121 fi
122 if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then
123 echo "Running libtoolize..."
124 libtoolize --force --copy
125 fi
126 echo "Running aclocal $aclocalinclude ..."
127 aclocal $aclocalinclude
128 if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then
129 echo "Running autoheader..."
130 autoheader
131 fi
132 echo "Running automake --gnu $am_opt ..."
133 automake --add-missing --gnu $am_opt
134 echo "Running autoconf ..."
135 autoconf
136 )
137 fi
138done
139
140#conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c
141
142if test x$NOCONFIGURE = x; then
143 echo Running $srcdir/configure $conf_flags "$@" ...
144 $srcdir/configure $conf_flags "$@" \
145 && echo Now type \`make\' to compile $PKG_NAME
146else
147 echo Skipping configure process.
148fi
diff --git a/legacy/ecore/configure.in b/legacy/ecore/configure.in
new file mode 100644
index 0000000000..04afa739a2
--- /dev/null
+++ b/legacy/ecore/configure.in
@@ -0,0 +1,61 @@
1dnl Process this file with autoconf to produce a configure script.
2
3AC_INIT(configure.in)
4AM_INIT_AUTOMAKE(libecore, 0.1)
5AM_CONFIG_HEADER(config.h)
6
7AC_ISC_POSIX
8AC_PROG_CC
9AM_PROG_CC_STDC
10AC_HEADER_STDC
11AM_PROG_LIBTOOL
12
13AM_WITH_DMALLOC
14
15dnl Set PACKAGE_LOCALE_DIR in config.h.
16if test "x${prefix}" = "xNONE"; then
17 AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${ac_default_prefix}/${DATADIRNAME}/locale")
18else
19 AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale")
20fi
21
22dnl Set PACKAGE_DATA_DIR in config.h.
23if test "x${datadir}" = 'x${prefix}/share'; then
24 if test "x${prefix}" = "xNONE"; then
25 AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${ac_default_prefix}/share/${PACKAGE}")
26 else
27 AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${prefix}/share/${PACKAGE}")
28 fi
29else
30 AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${datadir}/${PACKAGE}")
31fi
32
33dnl Set PACKAGE_SOURCE_DIR in config.h.
34packagesrcdir=`cd $srcdir && pwd`
35AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}")
36
37dnl Use -Wall if we have gcc.
38changequote(,)dnl
39if test "x$GCC" = "xyes"; then
40 case " $CFLAGS " in
41 *[\ \ ]-Wall[\ \ ]*) ;;
42 *) CFLAGS="$CFLAGS -Wall" ;;
43 esac
44fi
45changequote([,])dnl
46
47evas_cflags=`evas-config --cflags`
48evas_libs=`evas-config --libs`
49edb_cflags=`edb-config --cflags`
50edb_libs=`edb-config --libs`
51
52AC_SUBST(evas_cflags)
53AC_SUBST(evas_libs)
54AC_SUBST(edb_cflags)
55AC_SUBST(edb_libs)
56
57AC_OUTPUT([
58Makefile
59src/Makefile
60])
61
diff --git a/legacy/ecore/src/.cvsignore b/legacy/ecore/src/.cvsignore
new file mode 100644
index 0000000000..dd4706c923
--- /dev/null
+++ b/legacy/ecore/src/.cvsignore
@@ -0,0 +1,29 @@
1*.lo
2*.la
3.deps
4.libs
5Makefile
6Makefile.in
7aclocal.m4
8confdefs.h
9config.cache
10config.guess
11config.h
12config.h.in
13config.log
14config.status
15config.sub
16configure
17install-sh
18libtool
19ltconfig
20ltmain.sh
21missing
22mkinstalldirs
23stamp-h
24stamp-h.in
25*.tar.gz
26macros
27*~
28*.spec
29.icons
diff --git a/legacy/ecore/src/Makefile.am b/legacy/ecore/src/Makefile.am
new file mode 100644
index 0000000000..fdb16e9ca9
--- /dev/null
+++ b/legacy/ecore/src/Makefile.am
@@ -0,0 +1,19 @@
1## Process this file with automake to produce Makefile.in
2
3INCLUDES = \
4 @evas_cflags@ @edb_cflags@
5
6lib_LTLIBRARIES = libecore.la
7
8libecore_la_SOURCES = \
9 e_ev_filter.c e_ev_filter.h \
10 e_ev_signal.c e_ev_signal.h \
11 e_ev_x.c e_ev_x.h \
12 e_events.c e_events.h \
13 e_mem.c e_mem.h \
14 e_str.c e_str.h \
15 e_util.c e_util.h \
16 e_x.c e_x.h
17
18libecore_la_LIBADD = @evas_libs@ @edb_libs@ -lm
19
diff --git a/legacy/ecore/src/e_ev_filter.c b/legacy/ecore/src/e_ev_filter.c
new file mode 100644
index 0000000000..762467fc7a
--- /dev/null
+++ b/legacy/ecore/src/e_ev_filter.c
@@ -0,0 +1,128 @@
1#include "e_ev_filter.h"
2#include "e_str.h"
3#include "e_mem.h"
4#include "e_util.h"
5
6typedef struct _ev_handler Ev_Handler;
7typedef struct _ev_idle_handler Ev_Idle_Handler;
8
9struct _ev_handler
10{
11 void (*func) (Eevent * ev);
12 Ev_Handler *next;
13};
14
15struct _ev_idle_handler
16{
17 void (*func) (void *data);
18 void *data;
19 Ev_Idle_Handler *next;
20};
21
22static Ev_Handler *handler[EV_MAX];
23static Ev_Idle_Handler *idle_handlers = NULL;
24
25void
26e_event_filter(Eevent * ev)
27{
28 Eevent *evp;
29 int motion_events = 0;
30 int dnd_pos_events = 0;
31 int dnd_status_events = 0;
32
33 /* count events to only use last events of some types */
34 for (evp = ev; evp; evp = evp->next)
35 {
36 if (evp->type == EV_MOUSE_MOVE)
37 motion_events++;
38 if (evp->type == EV_DND_DROP_POSITION)
39 dnd_pos_events++;
40 if (evp->type == EV_DND_DROP_STATUS)
41 dnd_status_events++;
42 }
43 for (evp = ev; evp; evp = evp->next)
44 {
45 if (evp->type == EV_MOUSE_MOVE)
46 {
47 if (motion_events > 1)
48 {
49 evp->ignore = 1;
50 motion_events--;
51 }
52 }
53 else if (evp->type == EV_DND_DROP_POSITION)
54 {
55 if (dnd_pos_events > 1)
56 {
57 evp->ignore = 1;
58 dnd_pos_events--;
59 }
60 }
61 else if (evp->type == EV_DND_DROP_STATUS)
62 {
63 if (dnd_status_events > 1)
64 {
65 evp->ignore = 1;
66 dnd_status_events--;
67 }
68 }
69 }
70}
71
72void
73e_event_filter_events_handle(Eevent * ev)
74{
75 Eevent *evp;
76
77 for (evp = ev; evp; evp = evp->next)
78 {
79 Ev_Handler *h;
80
81 for (h = handler[evp->type]; h; h = h->next)
82 {
83 if ((!evp->ignore) && (h->func))
84 h->func(evp);
85 }
86 }
87}
88
89void
90e_event_filter_idle_handle(void)
91{
92 Ev_Idle_Handler *h;
93
94 for (h = idle_handlers; h; h = h->next)
95 h->func(h->data);
96}
97
98void
99e_event_filter_init(void)
100{
101 int i;
102
103 for (i = 0; i < EV_MAX; i++)
104 handler[i] = NULL;
105}
106
107void
108e_event_filter_handler_add(Eevent_Type type, void (*func) (Eevent * ev))
109{
110 Ev_Handler *h;
111
112 h = NEW(Ev_Handler, 1);
113 h->func = func;
114 h->next = handler[type];
115 handler[type] = h;
116}
117
118void
119e_event_filter_idle_handler_add(void (*func) (void *data), void *data)
120{
121 Ev_Idle_Handler *h;
122
123 h = NEW(Ev_Idle_Handler, 1);
124 h->func = func;
125 h->data = data;
126 h->next = idle_handlers;
127 idle_handlers = h;
128}
diff --git a/legacy/ecore/src/e_ev_filter.h b/legacy/ecore/src/e_ev_filter.h
new file mode 100644
index 0000000000..a0c0b080f4
--- /dev/null
+++ b/legacy/ecore/src/e_ev_filter.h
@@ -0,0 +1,15 @@
1#ifndef E_EV_FILTER_H
2#define E_EV_FILTER_H 1
3
4#include "e_events.h"
5
6void e_event_filter(Eevent * ev);
7void e_event_filter_events_handle(Eevent * ev);
8void e_event_filter_idle_handle(void);
9void e_event_filter_init(void);
10void e_event_filter_handler_add(Eevent_Type type,
11 void (*func) (Eevent * ev));
12void e_event_filter_idle_handler_add(void (*func) (void *data),
13
14 void *data);
15#endif
diff --git a/legacy/ecore/src/e_ev_signal.c b/legacy/ecore/src/e_ev_signal.c
new file mode 100644
index 0000000000..438d3969ad
--- /dev/null
+++ b/legacy/ecore/src/e_ev_signal.c
@@ -0,0 +1,323 @@
1#include "e_events.h"
2#include "e_ev_signal.h"
3#include "e_str.h"
4#include "e_mem.h"
5#include "e_util.h"
6#include <sys/types.h>
7#include <sys/wait.h>
8#include <signal.h>
9#include <errno.h>
10
11static void e_ev_signal_free(void *event);
12static void e_ev_signal_handle_sigchld(int num);
13static void e_ev_signal_handle_sigusr1(int num);
14static void e_ev_signal_handle_sigusr2(int num);
15static void e_ev_signal_handle_sighup(int num);
16static void e_ev_signal_handle_sigpipe(int num);
17static void e_ev_signal_handle_sigsegv(int num);
18static void e_ev_signal_handle_sigfpe(int num);
19static void e_ev_signal_handle_sigill(int num);
20static void e_ev_signal_handle_sigbus(int num);
21
22#ifdef HAVE_SIGSTKFLT
23static void e_ev_signal_handle_sigstkflt(int num);
24#endif
25#ifdef HAVE_SIGPWR
26static void e_ev_signal_handle_sigpwr(int num);
27#endif
28static void e_ev_signal_handle_sigchld(int num);
29static void e_ev_signal_handle_all(pid_t pid);
30
31static int signal_chld_count = 0;
32static int signal_usr1_count = 0;
33static int signal_usr2_count = 0;
34static int signal_hup_count = 0;
35
36/* freeing stuff */
37static void
38e_ev_signal_free(void *event)
39{
40 FREE(event);
41}
42
43/* signal handlers we can return from and add to signal recieved counts */
44static void
45e_ev_signal_handle_sigchld(int num)
46{
47 signal_chld_count++;
48 return;
49 num = 0;
50}
51
52static void
53e_ev_signal_handle_sigusr1(int num)
54{
55 signal_usr1_count++;
56 return;
57 num = 0;
58}
59
60static void
61e_ev_signal_handle_sigusr2(int num)
62{
63 signal_usr2_count++;
64 return;
65 num = 0;
66}
67
68static void
69e_ev_signal_handle_sighup(int num)
70{
71 signal_hup_count++;
72 return;
73 num = 0;
74}
75
76/* signals to ignore */
77static void
78e_ev_signal_handle_sigpipe(int num)
79{
80 return;
81 num = 0;
82}
83
84/* signal handlers we cant return from - so handle here */
85static void
86e_ev_signal_handle_sigsegv(int num)
87{
88 for (;;)
89 {
90 fprintf(stderr, "EEEEEEEEK SEGV - waiting 10 seconds\n");
91 sleep(10);
92 }
93 /* EEK - can't return - bad */
94 abort();
95 num = 0;
96}
97
98static void
99e_ev_signal_handle_sigfpe(int num)
100{
101 /* EEK - can't return - bad */
102 abort();
103 num = 0;
104}
105
106static void
107e_ev_signal_handle_sigill(int num)
108{
109 /* EEK - can't return - bad */
110 abort();
111 num = 0;
112}
113
114static void
115e_ev_signal_handle_sigbus(int num)
116{
117 /* EEK - can't return - bad */
118 abort();
119 num = 0;
120}
121
122#ifdef HAVE_SIGSTKFLT
123static void
124e_ev_signal_handle_sigstkflt(int num)
125{
126 /* EEK - can't return - bad */
127 abort();
128 return;
129 num = 0;
130}
131#endif
132
133static void
134e_ev_signal_handle_sigint(int num)
135{
136 exit(0);
137 return;
138 num = 0;
139}
140
141static void
142e_ev_signal_handle_sigquit(int num)
143{
144 exit(0);
145 return;
146 num = 0;
147}
148
149static void
150e_ev_signal_handle_sigabrt(int num)
151{
152 abort();
153 return;
154 num = 0;
155}
156
157static void
158e_ev_signal_handle_sigalrm(int num)
159{
160 return;
161 num = 0;
162}
163
164static void
165e_ev_signal_handle_sigterm(int num)
166{
167 exit(0);
168 return;
169 num = 0;
170}
171
172#ifdef HAVE_SIGPWR
173static void
174e_ev_signal_handle_sigpwr(int num)
175{
176 exit(0);
177 return;
178 num = 0;
179}
180#endif
181
182static void
183e_ev_signal_handle_all(pid_t pid_pass)
184{
185 int status;
186 pid_t pid;
187
188 if (signal_chld_count > 0)
189 {
190 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
191 {
192 if (WIFEXITED(status))
193 {
194 Ev_Child *e;
195 int code;
196
197 code = WEXITSTATUS(status);
198 e = NEW(Ev_Child, 1);
199 e->pid = pid;
200 e->exit_code = code;
201 e_add_event(EV_CHILD, e, e_ev_signal_free);
202 }
203 }
204 signal_chld_count = 0;
205 }
206 while (signal_usr1_count > 0)
207 {
208 Ev_User *e;
209
210 e = NEW(Ev_User, 1);
211 e->num = 0;
212 e->hup = 0;
213 e_add_event(EV_USER, e, e_ev_signal_free);
214 signal_usr1_count--;
215 }
216 while (signal_hup_count > 0)
217 {
218 Ev_User *e;
219
220 e = NEW(Ev_User, 1);
221 e->num = 0;
222 e->hup = 1;
223 e_add_event(EV_USER, e, e_ev_signal_free);
224 signal_hup_count--;
225 }
226 return;
227 pid_pass = 0;
228}
229
230int
231e_ev_signal_events_pending(void)
232{
233 return (signal_chld_count + signal_usr1_count + signal_hup_count);
234}
235
236void
237e_ev_signal_init(void)
238{
239 struct sigaction sa;
240
241 e_add_event_pid(0, e_ev_signal_handle_all);
242
243 sa.sa_handler = e_ev_signal_handle_sigchld;
244 sa.sa_flags = SA_RESTART;
245 sigemptyset(&sa.sa_mask);
246 sigaction(SIGCHLD, &sa, (struct sigaction *)0);
247
248 sa.sa_handler = e_ev_signal_handle_sigusr1;
249 sa.sa_flags = SA_RESTART;
250 sigemptyset(&sa.sa_mask);
251 sigaction(SIGUSR1, &sa, (struct sigaction *)0);
252
253 sa.sa_handler = e_ev_signal_handle_sigusr2;
254 sa.sa_flags = SA_RESTART;
255 sigemptyset(&sa.sa_mask);
256 sigaction(SIGUSR2, &sa, (struct sigaction *)0);
257
258 sa.sa_handler = e_ev_signal_handle_sighup;
259 sa.sa_flags = SA_RESTART;
260 sigemptyset(&sa.sa_mask);
261 sigaction(SIGHUP, &sa, (struct sigaction *)0);
262
263 sa.sa_handler = e_ev_signal_handle_sigpipe;
264 sa.sa_flags = SA_RESTART;
265 sigemptyset(&sa.sa_mask);
266 sigaction(SIGPIPE, &sa, (struct sigaction *)0);
267
268 sa.sa_handler = e_ev_signal_handle_sigsegv;
269 sa.sa_flags = SA_RESTART;
270 sigemptyset(&sa.sa_mask);
271 sigaction(SIGSEGV, &sa, (struct sigaction *)0);
272
273 sa.sa_handler = e_ev_signal_handle_sigfpe;
274 sa.sa_flags = SA_RESTART;
275 sigemptyset(&sa.sa_mask);
276 sigaction(SIGFPE, &sa, (struct sigaction *)0);
277
278 sa.sa_handler = e_ev_signal_handle_sigill;
279 sa.sa_flags = SA_RESTART;
280 sigemptyset(&sa.sa_mask);
281 sigaction(SIGILL, &sa, (struct sigaction *)0);
282
283 sa.sa_handler = e_ev_signal_handle_sigbus;
284 sa.sa_flags = SA_RESTART;
285 sigemptyset(&sa.sa_mask);
286 sigaction(SIGBUS, &sa, (struct sigaction *)0);
287#ifdef HAVE_SIGSTKFLT
288 sa.sa_handler = e_ev_signal_handle_sigstkflt;
289 sa.sa_flags = SA_RESTART;
290 sigemptyset(&sa.sa_mask);
291 sigaction(SIGSTKFLT, &sa, (struct sigaction *)0);
292#endif
293 sa.sa_handler = e_ev_signal_handle_sigint;
294 sa.sa_flags = SA_RESTART;
295 sigemptyset(&sa.sa_mask);
296 sigaction(SIGINT, &sa, (struct sigaction *)0);
297
298 sa.sa_handler = e_ev_signal_handle_sigquit;
299 sa.sa_flags = SA_RESTART;
300 sigemptyset(&sa.sa_mask);
301 sigaction(SIGQUIT, &sa, (struct sigaction *)0);
302
303 sa.sa_handler = e_ev_signal_handle_sigabrt;
304 sa.sa_flags = SA_RESTART;
305 sigemptyset(&sa.sa_mask);
306 sigaction(SIGABRT, &sa, (struct sigaction *)0);
307
308 sa.sa_handler = e_ev_signal_handle_sigalrm;
309 sa.sa_flags = SA_RESTART;
310 sigemptyset(&sa.sa_mask);
311 sigaction(SIGALRM, &sa, (struct sigaction *)0);
312
313 sa.sa_handler = e_ev_signal_handle_sigterm;
314 sa.sa_flags = SA_RESTART;
315 sigemptyset(&sa.sa_mask);
316 sigaction(SIGTERM, &sa, (struct sigaction *)0);
317#ifdef HAVE_SIGPWR
318 sa.sa_handler = e_ev_signal_handle_sigpwr;
319 sa.sa_flags = SA_RESTART;
320 sigemptyset(&sa.sa_mask);
321 sigaction(SIGPWR, &sa, (struct sigaction *)0);
322#endif
323}
diff --git a/legacy/ecore/src/e_ev_signal.h b/legacy/ecore/src/e_ev_signal.h
new file mode 100644
index 0000000000..74e926263d
--- /dev/null
+++ b/legacy/ecore/src/e_ev_signal.h
@@ -0,0 +1,5 @@
1#ifndef E_EV_SIGNAL_H
2#define E_EV_SIGNAL_H 1
3void e_ev_signal_init(void);
4int e_ev_signal_events_pending(void);
5#endif
diff --git a/legacy/ecore/src/e_ev_x.c b/legacy/ecore/src/e_ev_x.c
new file mode 100644
index 0000000000..8e4898c259
--- /dev/null
+++ b/legacy/ecore/src/e_ev_x.c
@@ -0,0 +1,1029 @@
1#include "e_events.h"
2#include "e_ev_x.h"
3#include "e_str.h"
4#include "e_mem.h"
5#include "e_util.h"
6
7/* private funtion prototypes */
8static void e_ev_x_handle_events(int fd);
9static void e_ev_x_translate_events(XEvent * events, int num_events);
10
11static void e_ev_key_down_free(void *event);
12static void e_ev_key_up_free(void *event);
13static void e_ev_generic_free(void *event);
14static void e_ev_dnd_drop_request_free(void *event);
15
16static void e_ev_x_handle_key_press(XEvent * xevent);
17static void e_ev_x_handle_key_release(XEvent * xevent);
18static void e_ev_x_handle_button_press(XEvent * xevent);
19static void e_ev_x_handle_button_release(XEvent * xevent);
20static void e_ev_x_handle_motion_notify(XEvent * xevent);
21static void e_ev_x_handle_enter_notify(XEvent * xevent);
22static void e_ev_x_handle_leave_notify(XEvent * xevent);
23static void e_ev_x_handle_focus_in(XEvent * xevent);
24static void e_ev_x_handle_focus_out(XEvent * xevent);
25static void e_ev_x_handle_expose(XEvent * xevent);
26static void e_ev_x_handle_visibility_notify(XEvent * xevent);
27static void e_ev_x_handle_create_notify(XEvent * xevent);
28static void e_ev_x_handle_destroy_notify(XEvent * xevent);
29static void e_ev_x_handle_unmap_notify(XEvent * xevent);
30static void e_ev_x_handle_map_notify(XEvent * xevent);
31static void e_ev_x_handle_map_request(XEvent * xevent);
32static void e_ev_x_handle_reparent_notify(XEvent * xevent);
33static void e_ev_x_handle_configure_notify(XEvent * xevent);
34static void e_ev_x_handle_configure_request(XEvent * xevent);
35static void e_ev_x_handle_circulate_notify(XEvent * xevent);
36static void e_ev_x_handle_circulate_request(XEvent * xevent);
37static void e_ev_x_handle_property_notify(XEvent * xevent);
38static void e_ev_x_handle_colormap_notify(XEvent * xevent);
39static void e_ev_x_handle_selection_notify(XEvent * xevent);
40static void e_ev_x_handle_selection_request(XEvent * xevent);
41static void e_ev_x_handle_client_message(XEvent * xevent);
42static void e_ev_x_handle_shape_change(XEvent * xevent);
43
44static int max_event_id = 0;
45static void (**event_translator) (XEvent * event) = NULL;
46
47static int lock_mask_scroll = 0, lock_mask_num = 0, lock_mask_caps = 0;
48static int mod_mask_shift = 0, mod_mask_ctrl = 0, mod_mask_alt =
49 0, mod_mask_win = 0;
50
51/* convenience macros */
52#define GETSET_MODS(state, mods) \
53(mods) = EV_KEY_MODIFIER_NONE;\
54if ((state) & mod_mask_shift) { e_mod_shift_set(1); (mods) |= EV_KEY_MODIFIER_SHIFT; }\
55else e_mod_shift_set(0);\
56if ((state) & mod_mask_ctrl) { e_mod_ctrl_set(1); (mods) |= EV_KEY_MODIFIER_CTRL; }\
57else e_mod_ctrl_set(0);\
58if ((state) & mod_mask_alt) { e_mod_alt_set(1); (mods) |= EV_KEY_MODIFIER_ALT; }\
59else e_mod_alt_set(0);\
60if ((state) & mod_mask_win) { e_mod_win_set(1); (mods) |= EV_KEY_MODIFIER_WIN; }\
61else e_mod_win_set(0);
62
63/* public functions */
64
65/* initialise event handling for the fd X is on */
66void
67e_ev_x_init(void)
68{
69 int i, shape_event_id, current_lock;
70
71 shape_event_id = max_event_id = e_event_shape_get_id();
72 event_translator = NEW_PTR(max_event_id + 1);
73 for (i = 0; i < max_event_id + 1; i++)
74 event_translator[i] = NULL;
75 event_translator[KeyPress] = e_ev_x_handle_key_press;
76 event_translator[KeyRelease] = e_ev_x_handle_key_release;
77 event_translator[ButtonPress] = e_ev_x_handle_button_press;
78 event_translator[ButtonRelease] = e_ev_x_handle_button_release;
79 event_translator[MotionNotify] = e_ev_x_handle_motion_notify;
80 event_translator[EnterNotify] = e_ev_x_handle_enter_notify;
81 event_translator[LeaveNotify] = e_ev_x_handle_leave_notify;
82 event_translator[FocusIn] = e_ev_x_handle_focus_in;
83 event_translator[FocusOut] = e_ev_x_handle_focus_out;
84 event_translator[Expose] = e_ev_x_handle_expose;
85 event_translator[VisibilityNotify] = e_ev_x_handle_visibility_notify;
86 event_translator[CreateNotify] = e_ev_x_handle_create_notify;
87 event_translator[DestroyNotify] = e_ev_x_handle_destroy_notify;
88 event_translator[UnmapNotify] = e_ev_x_handle_unmap_notify;
89 event_translator[MapNotify] = e_ev_x_handle_map_notify;
90 event_translator[MapRequest] = e_ev_x_handle_map_request;
91 event_translator[ReparentNotify] = e_ev_x_handle_reparent_notify;
92 event_translator[ConfigureNotify] = e_ev_x_handle_configure_notify;
93 event_translator[ConfigureRequest] = e_ev_x_handle_configure_request;
94 event_translator[CirculateNotify] = e_ev_x_handle_circulate_notify;
95 event_translator[CirculateRequest] = e_ev_x_handle_circulate_request;
96 event_translator[PropertyNotify] = e_ev_x_handle_property_notify;
97 event_translator[ColormapNotify] = e_ev_x_handle_colormap_notify;
98 event_translator[ClientMessage] = e_ev_x_handle_client_message;
99 event_translator[SelectionNotify] = e_ev_x_handle_selection_notify;
100 event_translator[SelectionRequest] = e_ev_x_handle_selection_request;
101 event_translator[shape_event_id] = e_ev_x_handle_shape_change;
102
103 lock_mask_scroll = e_lock_mask_num_get();
104 lock_mask_num = e_lock_mask_num_get();
105 lock_mask_caps = e_lock_mask_scroll_get();
106
107 mod_mask_shift = e_mod_mask_shift_get();
108 mod_mask_ctrl = e_mod_mask_ctrl_get();
109 mod_mask_alt = e_mod_mask_alt_get();
110 mod_mask_win = e_mod_mask_win_get();
111
112 e_key_grab("Num_Lock", EV_KEY_MODIFIER_NONE, 1, 1);
113 e_key_grab("Scroll_Lock", EV_KEY_MODIFIER_NONE, 1, 1);
114 e_key_grab("Caps_Lock", EV_KEY_MODIFIER_NONE, 1, 1);
115 current_lock = e_modifier_mask_get();
116 if (current_lock & lock_mask_scroll)
117 e_lock_scroll_set(1);
118 if (current_lock & lock_mask_num)
119 e_lock_num_set(1);
120 if (current_lock & lock_mask_caps)
121 e_lock_caps_set(1);
122 if (current_lock & mod_mask_shift)
123 e_mod_shift_set(1);
124 if (current_lock & mod_mask_ctrl)
125 e_mod_ctrl_set(1);
126 if (current_lock & mod_mask_alt)
127 e_mod_alt_set(1);
128 if (current_lock & mod_mask_win)
129 e_mod_win_set(1);
130 e_add_event_fd(e_x_get_fd(), e_ev_x_handle_events);
131}
132
133/* private functions */
134/* get all events onthe event queue and translate them */
135static void
136e_ev_x_handle_events(int fd)
137{
138 int num_events = 0, size_events = 0;
139 XEvent *events = NULL;
140
141 /* while there are events in the queue */
142 while (e_events_pending())
143 {
144 /* incriment our event count */
145 num_events++;
146 /* if the numebr fo events is > than our buffer size then */
147 if (num_events > size_events)
148 {
149 /* increase the buffer size by 64 events */
150 size_events += 64;
151 if (events)
152 {
153 REALLOC(events, XEvent, size_events)}
154 else
155 events = NEW(XEvent, size_events);
156 }
157 /* get the next event into the event buffer */
158 e_get_next_event(&(events[num_events - 1]));
159 }
160 /* call the XEvent -> Eevent translator */
161 if (events)
162 {
163 e_ev_x_translate_events(events, num_events);
164 /* if theres an event buffer - free it */
165 FREE(events);
166 }
167 return;
168 fd = 0;
169}
170
171/* take an array of events and translate them into E events */
172static void
173e_ev_x_translate_events(XEvent * events, int num_events)
174{
175 int i;
176
177 for (i = 0; i < num_events; i++)
178 {
179 if ((events[i].type < max_event_id) &&
180 (event_translator[events[i].type]))
181 (*(event_translator[events[i].type])) (&(events[i]));
182 }
183}
184
185static void
186e_ev_key_down_free(void *event)
187{
188 Ev_Key_Down *e;
189
190 e = (Ev_Key_Down *) event;
191 IF_FREE(e->key);
192 IF_FREE(e->compose);
193 FREE(e);
194}
195
196static void
197e_ev_key_up_free(void *event)
198{
199 Ev_Key_Up *e;
200
201 e = (Ev_Key_Up *) event;
202 IF_FREE(e->key);
203 IF_FREE(e->compose);
204 FREE(e);
205}
206
207static void
208e_ev_generic_free(void *event)
209{
210 FREE(event);
211}
212
213static void
214e_ev_dnd_drop_request_free(void *event)
215{
216 Ev_Dnd_Drop_Request *e;
217
218 e = (Ev_Dnd_Drop_Request *) event;
219 if (e->files)
220 e_string_free_list(e->files, e->num_files);
221 FREE(event);
222}
223
224static void
225e_ev_x_handle_key_press(XEvent * xevent)
226{
227 Ev_Key_Down *e;
228 static KeyCode previous_code = 0;
229 static Time previous_time = 0;
230
231 /* avoid doubling events up from passive grabs */
232 if ((xevent->xkey.keycode == previous_code) &&
233 xevent->xkey.time == previous_time)
234 return;
235 previous_code = xevent->xkey.keycode;
236 previous_time = xevent->xkey.time;
237 if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Scroll_Lock)
238 {
239 if (e_lock_scroll_get())
240 e_lock_scroll_set(0);
241 else
242 e_lock_scroll_set(1);
243 e_event_allow(ReplayKeyboard, xevent->xkey.time);
244 e_flush();
245 }
246 else if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Num_Lock)
247 {
248 if (e_lock_num_get())
249 e_lock_num_set(0);
250 else
251 e_lock_num_set(1);
252 e_event_allow(ReplayKeyboard, xevent->xkey.time);
253 e_flush();
254 }
255 else if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Caps_Lock)
256 {
257 if (e_lock_caps_get())
258 e_lock_caps_set(0);
259 else
260 e_lock_caps_set(1);
261 e_event_allow(ReplayKeyboard, xevent->xkey.time);
262 e_flush();
263 }
264 e = NEW(Ev_Key_Down, 1);
265 e->win = xevent->xkey.window;
266 e->root = xevent->xkey.root;
267 GETSET_MODS(xevent->xkey.state, e->mods);
268 e->time = xevent->xkey.time;
269 e->key = e_key_get_string_from_keycode(xevent->xkey.keycode);
270 {
271 int val;
272 char buf[256];
273 KeySym sym;
274 XComposeStatus stat;
275
276 val = XLookupString((XKeyEvent *) xevent, buf, sizeof(buf), &sym, &stat);
277 if (val > 0)
278 {
279 buf[val] = 0;
280 e->compose = e_string_dup(buf);
281 }
282 else
283 e->compose = NULL;
284 }
285 e_add_event(EV_KEY_DOWN, e, e_ev_key_down_free);
286}
287
288static void
289e_ev_x_handle_key_release(XEvent * xevent)
290{
291 Ev_Key_Up *e;
292 static KeyCode previous_code = 0;
293 static Time previous_time = 0;
294
295 /* avoid doubling events up from passive grabs */
296 if ((xevent->xkey.keycode == previous_code) &&
297 xevent->xkey.time == previous_time)
298 return;
299 previous_code = xevent->xkey.keycode;
300 previous_time = xevent->xkey.time;
301
302 e = NEW(Ev_Key_Up, 1);
303 e->win = xevent->xkey.window;
304 e->root = xevent->xkey.root;
305 GETSET_MODS(xevent->xkey.state, e->mods);
306 e->time = xevent->xkey.time;
307 e->key = e_key_get_string_from_keycode(xevent->xkey.keycode);
308 {
309 int val;
310 char buf[256];
311 KeySym sym;
312 XComposeStatus stat;
313
314 val = XLookupString((XKeyEvent *) xevent, buf, sizeof(buf), &sym, &stat);
315 if (val > 0)
316 {
317 buf[val] = 0;
318 e->compose = e_string_dup(buf);
319 }
320 else
321 e->compose = NULL;
322 }
323 e_add_event(EV_KEY_UP, e, e_ev_key_up_free);
324}
325
326static void
327e_ev_x_handle_button_press(XEvent * xevent)
328{
329 static Time last_time = 0, last_last_time = 0;
330 static int last_button = 0, last_last_button = 0;
331 static Window last_window = 0, last_last_window = 0;
332
333 e_pointer_xy_set(xevent->xbutton.x_root, xevent->xbutton.y_root);
334 if ((xevent->xbutton.button == 4) || (xevent->xbutton.button == 5))
335 {
336 Ev_Wheel *e;
337
338 e = NEW(Ev_Wheel, 1);
339 e->win = xevent->xbutton.window;
340 e->root = xevent->xbutton.root;
341 e->x = xevent->xbutton.x;
342 e->y = xevent->xbutton.y;
343 e->rx = xevent->xbutton.x_root;
344 e->ry = xevent->xbutton.y_root;
345 e->time = xevent->xbutton.time;
346 if (xevent->xbutton.button == 5)
347 e->z = 1;
348 else
349 e->z = -1;
350 if (xevent->xbutton.time - last_time < 15)
351 e->z *= 16;
352 else if (xevent->xbutton.time - last_time < 30)
353 e->z *= 4;
354 GETSET_MODS(xevent->xbutton.state, e->mods);
355 e_add_event(EV_MOUSE_WHEEL, e, e_ev_generic_free);
356 }
357 else
358 {
359 Ev_Mouse_Down *e;
360
361 e = NEW(Ev_Mouse_Down, 1);
362 e->win = xevent->xbutton.window;
363 e->root = xevent->xbutton.root;
364 e->button = xevent->xbutton.button;
365 e->x = xevent->xbutton.x;
366 e->y = xevent->xbutton.y;
367 e->rx = xevent->xbutton.x_root;
368 e->ry = xevent->xbutton.y_root;
369 e->time = xevent->xbutton.time;
370 e->double_click = 0;
371 e->triple_click = 0;
372 GETSET_MODS(xevent->xbutton.state, e->mods);
373 if (xevent->xbutton.time - last_last_time < 500)
374 {
375 if ((xevent->xbutton.window == (unsigned int)last_window) &&
376 (last_window == last_last_window) &&
377 (xevent->xbutton.button == (unsigned int)last_button) &&
378 (last_button == last_button))
379 e->triple_click = 1;
380 }
381 else if (xevent->xbutton.time - last_time < 250)
382 {
383 if ((xevent->xbutton.window == (unsigned int)last_window) &&
384 (xevent->xbutton.button == (unsigned int)last_button))
385 e->double_click = 1;
386 }
387 e_add_event(EV_MOUSE_DOWN, e, e_ev_generic_free);
388 }
389 last_last_window = last_window;
390 last_window = xevent->xbutton.window;
391 last_last_button = last_button;
392 last_button = xevent->xbutton.button;
393 last_last_time = last_time;
394 last_time = xevent->xbutton.time;
395}
396
397static void
398e_ev_x_handle_button_release(XEvent * xevent)
399{
400 Ev_Mouse_Up *e;
401
402 if (xevent->xbutton.button > 3)
403 return;
404
405 e = NEW(Ev_Mouse_Up, 1);
406 e->win = xevent->xbutton.window;
407 e->root = xevent->xbutton.root;
408 e->button = xevent->xbutton.button;
409 e->x = xevent->xbutton.x;
410 e->y = xevent->xbutton.y;
411 e->rx = xevent->xbutton.x_root;
412 e->ry = xevent->xbutton.y_root;
413 e->time = xevent->xbutton.time;
414 GETSET_MODS(xevent->xbutton.state, e->mods);
415 e_add_event(EV_MOUSE_UP, e, e_ev_generic_free);
416}
417
418static void
419e_ev_x_handle_motion_notify(XEvent * xevent)
420{
421 Ev_Mouse_Move *e;
422
423 e_pointer_xy_set(xevent->xmotion.x_root, xevent->xmotion.y_root);
424 e = NEW(Ev_Mouse_Move, 1);
425 e->win = xevent->xmotion.window;
426 e->root = xevent->xmotion.root;
427 e->x = xevent->xmotion.x;
428 e->y = xevent->xmotion.y;
429 e->rx = xevent->xmotion.x_root;
430 e->ry = xevent->xmotion.y_root;
431 e->time = xevent->xmotion.time;
432 GETSET_MODS(xevent->xmotion.state, e->mods);
433 e_add_event(EV_MOUSE_MOVE, e, e_ev_generic_free);
434}
435
436static void
437e_ev_x_handle_enter_notify(XEvent * xevent)
438{
439 Ev_Window_Enter *e;
440
441 e_pointer_xy_set(xevent->xcrossing.x_root, xevent->xcrossing.y_root);
442 e = NEW(Ev_Window_Enter, 1);
443 e->win = xevent->xcrossing.window;
444 e->root = xevent->xcrossing.root;
445 e->x = xevent->xcrossing.x;
446 e->y = xevent->xcrossing.y;
447 e->rx = xevent->xcrossing.x_root;
448 e->ry = xevent->xcrossing.y_root;
449 e->time = xevent->xcrossing.time;
450 GETSET_MODS(xevent->xcrossing.state, e->mods);
451 e_add_event(EV_MOUSE_IN, e, e_ev_generic_free);
452 e_window_mouse_set_in(e->win, 1);
453}
454
455static void
456e_ev_x_handle_leave_notify(XEvent * xevent)
457{
458 Ev_Window_Leave *e;
459
460 e_pointer_xy_set(xevent->xcrossing.x_root, xevent->xcrossing.y_root);
461 e = NEW(Ev_Window_Leave, 1);
462 e->win = xevent->xcrossing.window;
463 e->root = xevent->xcrossing.root;
464 e->x = xevent->xcrossing.x;
465 e->y = xevent->xcrossing.y;
466 e->rx = xevent->xcrossing.x_root;
467 e->ry = xevent->xcrossing.y_root;
468 e->time = xevent->xcrossing.time;
469 GETSET_MODS(xevent->xcrossing.state, e->mods);
470 e_add_event(EV_MOUSE_OUT, e, e_ev_generic_free);
471 e_window_mouse_set_in(e->win, 0);
472}
473
474static void
475e_ev_x_handle_focus_in(XEvent * xevent)
476{
477 Ev_Window_Focus_In *e;
478
479 e = NEW(Ev_Window_Focus_In, 1);
480 e->win = xevent->xfocus.window;
481 e->root = e_window_get_root(e->win);
482 e_add_event(EV_WINDOW_FOCUS_IN, e, e_ev_generic_free);
483 e_focus_window_set(e->win);
484}
485
486static void
487e_ev_x_handle_focus_out(XEvent * xevent)
488{
489 Ev_Window_Focus_Out *e;
490
491 e = NEW(Ev_Window_Focus_Out, 1);
492 e->win = xevent->xfocus.window;
493 e->root = e_window_get_root(e->win);
494 e_add_event(EV_WINDOW_FOCUS_OUT, e, e_ev_generic_free);
495 e_focus_window_set(0);
496}
497
498static void
499e_ev_x_handle_expose(XEvent * xevent)
500{
501 Ev_Window_Expose *e;
502
503 e = NEW(Ev_Window_Expose, 1);
504 e->win = xevent->xexpose.window;
505 e->root = e_window_get_root(e->win);
506 e->x = xevent->xexpose.x;
507 e->y = xevent->xexpose.y;
508 e->w = xevent->xexpose.width;
509 e->h = xevent->xexpose.height;
510 e_add_event(EV_WINDOW_EXPOSE, e, e_ev_generic_free);
511}
512
513static void
514e_ev_x_handle_visibility_notify(XEvent * xevent)
515{
516 if (xevent->xvisibility.state != VisibilityPartiallyObscured)
517 {
518 Ev_Window_Visibility *e;
519
520 e = NEW(Ev_Window_Visibility, 1);
521 e->win = xevent->xvisibility.window;
522 e->root = e_window_get_root(e->win);
523 if (xevent->xvisibility.state == VisibilityFullyObscured)
524 e->fully_obscured = 1;
525 else
526 e->fully_obscured = 0;
527 e_add_event(EV_WINDOW_VISIBILITY, e, e_ev_generic_free);
528 }
529}
530
531static void
532e_ev_x_handle_create_notify(XEvent * xevent)
533{
534 Ev_Window_Create *e;
535
536 e = NEW(Ev_Window_Create, 1);
537 e->win = xevent->xcreatewindow.window;
538 e_validate_xid(e->win);
539 e->root = e_window_get_root(e->win);
540 if (xevent->xcreatewindow.override_redirect)
541 e->override = 1;
542 else
543 e->override = 0;
544 e_add_event(EV_WINDOW_CREATE, e, e_ev_generic_free);
545}
546
547static void
548e_ev_x_handle_destroy_notify(XEvent * xevent)
549{
550 Ev_Window_Destroy *e;
551
552 e = NEW(Ev_Window_Destroy, 1);
553 e->win = xevent->xdestroywindow.window;
554 e->root = e_window_get_root(e->win);
555 e_add_event(EV_WINDOW_DESTROY, e, e_ev_generic_free);
556 e_unvalidate_xid(e->win);
557}
558
559static void
560e_ev_x_handle_unmap_notify(XEvent * xevent)
561{
562 Ev_Window_Unmap *e;
563 E_XID *xid = NULL;
564
565 e = NEW(Ev_Window_Unmap, 1);
566 e->win = xevent->xunmap.window;
567 e->root = e_window_get_root(e->win);
568 e_add_event(EV_WINDOW_UNMAP, e, e_ev_generic_free);
569 xid = e_validate_xid(e->win);
570 if (xid)
571 xid->mapped = 0;
572}
573
574static void
575e_ev_x_handle_map_notify(XEvent * xevent)
576{
577 Ev_Window_Map *e;
578 E_XID *xid = NULL;
579
580 e = NEW(Ev_Window_Map, 1);
581 e->win = xevent->xmap.window;
582 e->root = e_window_get_root(e->win);
583 e_add_event(EV_WINDOW_MAP, e, e_ev_generic_free);
584 xid = e_validate_xid(e->win);
585 if (xid)
586 xid->mapped = 1;
587}
588
589static void
590e_ev_x_handle_map_request(XEvent * xevent)
591{
592 Ev_Window_Map_Request *e;
593
594 e = NEW(Ev_Window_Map_Request, 1);
595 e->win = xevent->xmaprequest.window;
596 e->root = e_window_get_root(e->win);
597 e_add_event(EV_WINDOW_MAP_REQUEST, e, e_ev_generic_free);
598 e_validate_xid(e->win);
599}
600
601static void
602e_ev_x_handle_reparent_notify(XEvent * xevent)
603{
604 Ev_Window_Reparent *e;
605 Window parent;
606 E_XID *xid = NULL;
607
608 e = NEW(Ev_Window_Reparent, 1);
609 e->win = xevent->xreparent.window;
610 xid = e_validate_xid(e->win);
611 e->root = e_window_get_root(e->win);
612 parent = e_window_get_parent(e->win);
613 e->parent_from = parent;
614 e->parent = xevent->xreparent.parent;
615 e_validate_xid(e->parent);
616 e_del_child(parent, e->win);
617 e_add_child(xevent->xreparent.parent, xevent->xreparent.window);
618 if (xid)
619 xid->parent = e->parent;
620 e_add_event(EV_WINDOW_REPARENT, e, e_ev_generic_free);
621}
622
623static void
624e_ev_x_handle_configure_notify(XEvent * xevent)
625{
626 Ev_Window_Configure *e;
627 E_XID *xid;
628
629 e = NEW(Ev_Window_Configure, 1);
630 e->win = xevent->xconfigure.window;
631 e->root = e_window_get_root(e->win);
632 e->x = xevent->xconfigure.x;
633 e->y = xevent->xconfigure.y;
634 e->w = xevent->xconfigure.width;
635 e->h = xevent->xconfigure.height;
636 if (!xevent->xconfigure.send_event)
637 {
638 xid = e_validate_xid(e->win);
639 if (xid)
640 {
641 xid->x = e->x;
642 xid->y = e->y;
643 xid->w = e->w;
644 xid->h = e->h;
645 }
646 e->wm_generated = 0;
647 /* FIXME: dont handle redioing stack for xevent->xconfigure.above */
648 /* member (the window is stacked immediately in stack above this) */
649 }
650 else
651 e->wm_generated = 1;
652 e_add_event(EV_WINDOW_CONFIGURE, e, e_ev_generic_free);
653}
654
655static void
656e_ev_x_handle_configure_request(XEvent * xevent)
657{
658 Ev_Window_Configure_Request *e;
659
660 e = NEW(Ev_Window_Configure_Request, 1);
661 e->win = xevent->xconfigurerequest.window;
662 e->root = e_window_get_root(e->win);
663 e->x = xevent->xconfigurerequest.x;
664 e->y = xevent->xconfigurerequest.y;
665 e->w = xevent->xconfigurerequest.width;
666 e->h = xevent->xconfigurerequest.height;
667 e->stack_win = xevent->xconfigurerequest.above;
668 e->detail = xevent->xconfigurerequest.detail;
669 e->mask = xevent->xconfigurerequest.value_mask;
670 e_add_event(EV_WINDOW_CONFIGURE_REQUEST, e, e_ev_generic_free);
671}
672
673static void
674e_ev_x_handle_circulate_notify(XEvent * xevent)
675{
676 Ev_Window_Circulate *e;
677
678 e = NEW(Ev_Window_Circulate, 1);
679 e->win = xevent->xcirculate.window;
680 e->root = e_window_get_root(e->win);
681 if (xevent->xcirculate.place == PlaceOnBottom)
682 e->lower = 1;
683 else
684 e->lower = 0;
685 e_add_event(EV_WINDOW_CIRCULATE, e, e_ev_generic_free);
686}
687
688static void
689e_ev_x_handle_circulate_request(XEvent * xevent)
690{
691 Ev_Window_Circulate_Request *e;
692
693 e = NEW(Ev_Window_Circulate_Request, 1);
694 e->win = xevent->xcirculaterequest.window;
695 e->root = e_window_get_root(e->win);
696 if (xevent->xcirculaterequest.place == PlaceOnBottom)
697 e->lower = 1;
698 else
699 e->lower = 0;
700 e_add_event(EV_WINDOW_CIRCULATE_REQUEST, e, e_ev_generic_free);
701}
702
703static void
704e_ev_x_handle_property_notify(XEvent * xevent)
705{
706 Ev_Window_Property *e;
707
708 e = NEW(Ev_Window_Property, 1);
709 e->win = xevent->xproperty.window;
710 e->root = e_window_get_root(e->win);
711 e->atom = xevent->xproperty.atom;
712 e->time = xevent->xproperty.time;
713 e_add_event(EV_WINDOW_PROPERTY, e, e_ev_generic_free);
714}
715
716static void
717e_ev_x_handle_colormap_notify(XEvent * xevent)
718{
719 Ev_Colormap *e;
720
721 e = NEW(Ev_Colormap, 1);
722 e->win = xevent->xcolormap.window;
723 e->root = e_window_get_root(e->win);
724 e->cmap = xevent->xcolormap.colormap;
725 if (xevent->xcolormap.state == ColormapInstalled)
726 e->installed = 1;
727 else
728 e->installed = 0;
729 e_add_event(EV_COLORMAP, e, e_ev_generic_free);
730}
731
732Ev_Dnd_Drop_Request *ev_drop_request_pending = NULL;
733
734static void
735e_ev_x_handle_selection_notify(XEvent * xevent)
736{
737 Ev_Dnd_Drop_Request *e;
738 char *data;
739 int size;
740 static Atom atom_xdndactioncopy = 0;
741 static Atom atom_xdndactionmove = 0;
742 static Atom atom_xdndactionlink = 0;
743 static Atom atom_xdndactionask = 0;
744 static Atom atom_xdndactionlist = 0;
745
746 e = ev_drop_request_pending;
747 if (!e)
748 return;
749
750 E_ATOM(atom_xdndactioncopy, "XdndActionCopy");
751 E_ATOM(atom_xdndactionmove, "XdndActionMove");
752 E_ATOM(atom_xdndactionlink, "XdndActionLink");
753 E_ATOM(atom_xdndactionask, "XdndActionAsk");
754 E_ATOM(atom_xdndactionlist, "XdndActionList");
755 data = e_dnd_selection_get(xevent->xany.window, e->source_win,
756 xevent->xselection.property, &size);
757 if (data)
758 {
759 char *s, *buf;
760 int i, is;
761 Atom *method = NULL;
762
763 method = e_window_property_get(e->source_win,
764 atom_xdndactionlist, XA_ATOM, &is);
765 if (method)
766 {
767 e->copy = 0;
768 e->link = 0;
769 e->move = 0;
770 if (*method == atom_xdndactioncopy)
771 e->copy = 1;
772 else if (*method == atom_xdndactionmove)
773 e->move = 1;
774 else if (*method == atom_xdndactionlink)
775 e->link = 1;
776 FREE(method);
777 }
778 else
779 {
780 e->copy = 0;
781 e->link = 0;
782 e->move = 0;
783 }
784 s = data;
785 buf = NEW(char, size);
786
787 i = 0;
788 is = 0;
789 e->files = NULL;
790 while ((s[is]) && (is < size))
791 {
792 if ((i == 0) && (s[is] == '#'))
793 {
794 for (; ((s[is] != 0) && (s[is] != '\n')); is++);
795 }
796 else
797 {
798 if (s[is] != '\r')
799 {
800 buf[i++] = s[is];
801 }
802 else
803 {
804 buf[i] = 0;
805 e->num_files++;
806 if (e->files)
807 {
808 REALLOC_PTR(e->files, e->num_files);
809 }
810 else
811 e->files = NEW_PTR(e->num_files);
812 e->files[e->num_files - 1] = e_string_dup(buf);
813 buf[0] = 0;
814 i = 0;
815 is++;
816 }
817 is++;
818 }
819 }
820 FREE(buf);
821 FREE(data);
822 }
823 e_add_event(EV_DND_DROP_REQUEST, e, e_ev_dnd_drop_request_free);
824 ev_drop_request_pending = NULL;
825}
826
827static void
828e_ev_x_handle_selection_request(XEvent * xevent)
829{
830 static Atom atom_xdndselection = 0;
831 static Atom atom_text_plain = 0;
832 Ev_Dnd_Data_Request *e;
833
834 E_ATOM(atom_xdndselection, "XdndSelection");
835 E_ATOM(atom_text_plain, "text/plain");
836 if (xevent->xselectionrequest.selection == atom_xdndselection)
837 {
838 e = NEW(Ev_Dnd_Data_Request, 1);
839 e->win = xevent->xselectionrequest.owner;
840 e->root = e_window_get_root(e->win);
841 e->source_win = xevent->xselectionrequest.requestor;
842 if (xevent->xselectionrequest.target == atom_text_plain)
843 e->plain_text = 1;
844 else
845 e->plain_text = 0;
846 e->destination_atom = xevent->xselectionrequest.property;
847 e_add_event(EV_DND_DATA_REQUEST, e, e_ev_generic_free);
848 }
849}
850
851static void
852e_ev_x_handle_client_message(XEvent * xevent)
853{
854 static Atom atom_wm_delete_window = 0;
855 static Atom atom_wm_protocols = 0;
856 static Atom atom_xdndstatus = 0;
857 static Atom atom_xdndenter = 0;
858 static Atom atom_xdndleave = 0;
859 static Atom atom_xdndfinished = 0;
860 static Atom atom_xdndposition = 0;
861 static Atom atom_xdnddrop = 0;
862 static Atom atom_text_uri_list = 0;
863 static Atom atom_xdndactioncopy = 0;
864 static Atom atom_xdndactionlink = 0;
865 static Atom atom_xdndactionmove = 0;
866
867 /* setup some known atoms to translate this message into a sensible event */
868 E_ATOM(atom_wm_delete_window, "WM_DELETE_WINDOW");
869 E_ATOM(atom_wm_protocols, "WM_PROTOCOLS");
870 E_ATOM(atom_xdndstatus, "XdndStatus");
871 E_ATOM(atom_xdndfinished, "XdndFinished");
872 E_ATOM(atom_xdndenter, "XdndEnter");
873 E_ATOM(atom_xdndleave, "XdndLeave");
874 E_ATOM(atom_xdnddrop, "XdndDrop");
875 E_ATOM(atom_xdndposition, "XdndPosition");
876 E_ATOM(atom_xdndactioncopy, "XdndActionCopy");
877 E_ATOM(atom_xdndactionlink, "XdndActionLink");
878 E_ATOM(atom_xdndactionmove, "XdndActionMove");
879 E_ATOM(atom_text_uri_list, "text/uri-list");
880 /* forst type = delete event sent to client */
881 if ((xevent->xclient.message_type == atom_wm_protocols) &&
882 (xevent->xclient.format == 32) &&
883 (xevent->xclient.data.l[0] == (long)atom_wm_delete_window))
884 {
885 Ev_Window_Delete *e;
886
887 e = NEW(Ev_Window_Delete, 1);
888 e->win = xevent->xclient.window;
889 e->root = e_window_get_root(e->win);
890 e_add_event(EV_WINDOW_DELETE, e, e_ev_generic_free);
891 }
892 else if ((xevent->xclient.message_type == atom_xdndenter) &&
893 (xevent->xclient.format == 32))
894 {
895 if (xevent->xclient.data.l[2] == (long)atom_text_uri_list)
896 {
897 Ev_Dnd_Drop_Request *e;
898
899 if (ev_drop_request_pending)
900 {
901 e_ev_dnd_drop_request_free(ev_drop_request_pending);
902 ev_drop_request_pending = NULL;
903 }
904 e = NEW(Ev_Dnd_Drop_Request, 1);
905 e->win = xevent->xclient.window;
906 e->root = e_window_get_root(e->win);
907 e->source_win = (Window) xevent->xclient.data.l[0];
908 if (!e_dnd_selection_convert
909 (e->source_win, e->win, atom_text_uri_list))
910 {
911 FREE(e);
912 return;
913 }
914 e->files = NULL;
915 e->num_files = 0;
916 ev_drop_request_pending = e;
917 }
918 }
919 else if ((xevent->xclient.message_type == atom_xdndleave) &&
920 (xevent->xclient.format == 32))
921 {
922 Ev_Dnd_Drop_End *e;
923
924 e = NEW(Ev_Dnd_Drop_End, 1);
925 e->win = xevent->xclient.window;
926 e->root = e_window_get_root(e->win);
927 e->source_win = (Window) xevent->xclient.data.l[0];
928 e_add_event(EV_DND_DROP_END, e, e_ev_generic_free);
929 }
930 else if ((xevent->xclient.message_type == atom_xdndposition) &&
931 (xevent->xclient.format == 32))
932 {
933 Ev_Dnd_Drop_Position *e;
934
935 e = NEW(Ev_Dnd_Drop_Position, 1);
936 e->win = xevent->xclient.window;
937 e->root = e_window_get_root(e->win);
938 e->source_win = (Window) xevent->xclient.data.l[0];
939 e->x = (xevent->xclient.data.l[2] >> 16) & 0xffff;
940 e->y = xevent->xclient.data.l[2] & 0xffff;
941 e_add_event(EV_DND_DROP_POSITION, e, e_ev_generic_free);
942 }
943 else if ((xevent->xclient.message_type == atom_xdndstatus) &&
944 (xevent->xclient.format == 32))
945 {
946 Ev_Dnd_Drop_Status *e;
947
948 e = NEW(Ev_Dnd_Drop_Status, 1);
949 e->win = xevent->xclient.window;
950 e->root = e_window_get_root(e->win);
951 e->source_win = (Window) xevent->xclient.data.l[0];
952 e->x = (xevent->xclient.data.l[2] >> 16) & 0xffff;
953 e->y = xevent->xclient.data.l[2] & 0xffff;
954 e->w = (xevent->xclient.data.l[3] >> 16) & 0xffff;
955 e->h = xevent->xclient.data.l[3] & 0xffff;
956 if (xevent->xclient.data.l[1] & 0x1)
957 e->ok = 1;
958 else
959 e->ok = 0;
960 e_add_event(EV_DND_DROP_STATUS, e, e_ev_generic_free);
961 }
962 else if ((xevent->xclient.message_type == atom_xdndfinished) &&
963 (xevent->xclient.format == 32))
964 {
965 Ev_Dnd_Drop_End *e;
966
967 e = NEW(Ev_Dnd_Drop_End, 1);
968 e->win = xevent->xclient.window;
969 e->root = e_window_get_root(e->win);
970 e->source_win = (Window) xevent->xclient.data.l[0];
971 e_add_event(EV_DND_DROP_END, e, e_ev_generic_free);
972 }
973 else if ((xevent->xclient.message_type == atom_xdnddrop) &&
974 (xevent->xclient.format == 32))
975 {
976 Ev_Dnd_Drop *e;
977
978 e = NEW(Ev_Dnd_Drop, 1);
979 e->win = xevent->xclient.window;
980 e->root = e_window_get_root(e->win);
981 e->source_win = (Window) xevent->xclient.data.l[0];
982 e_add_event(EV_DND_DROP, e, e_ev_generic_free);
983 }
984 else
985 {
986 Ev_Message *e;
987
988 e = NEW(Ev_Message, 1);
989 e->win = xevent->xclient.window;
990 e->format = xevent->xclient.format;
991 e->atom = xevent->xclient.message_type;
992 MEMCPY(xevent->xclient.data.b, e->data.b, char, 20);
993
994 e_add_event(EV_MESSAGE, e, e_ev_generic_free);
995 }
996}
997
998static void
999e_ev_x_handle_shape_change(XEvent * xevent)
1000{
1001 Ev_Window_Shape *e;
1002 XShapeEvent *shape_event;
1003
1004 shape_event = (XShapeEvent *) xevent;
1005 e = NEW(Ev_Window_Shape, 1);
1006 e->win = shape_event->window;
1007 e->root = e_window_get_root(e->win);
1008 e->time = shape_event->time;
1009 e_add_event(EV_WINDOW_SHAPE, e, e_ev_generic_free);
1010}
1011
1012char *
1013e_key_press_translate_into_typeable(Ev_Key_Down * e)
1014{
1015 /* exceptions */
1016 if ((e_string_cmp(e->key, "Delete")) ||
1017 (e_string_cmp(e->key, "BackSpace")) ||
1018 (e_string_cmp(e->key, "Tab")) ||
1019 (e_string_cmp(e->key, "Escape")) ||
1020 (e_string_cmp(e->key, "Return")) ||
1021 (e_string_cmp(e->key, "KP_Enter")) ||
1022 (e_string_cmp(e->key, "Enter")) ||
1023 (e_string_cmp(e->key, "KP_Divide")) ||
1024 (e_string_cmp(e->key, "KP_Multiply")) ||
1025 (e_string_cmp(e->key, "KP_Subtract")) ||
1026 (e_string_cmp(e->key, "KP_Add")) || (e_string_cmp(e->key, "Enter")))
1027 return NULL;
1028 return e->compose;
1029}
diff --git a/legacy/ecore/src/e_ev_x.h b/legacy/ecore/src/e_ev_x.h
new file mode 100644
index 0000000000..c6ffaee33a
--- /dev/null
+++ b/legacy/ecore/src/e_ev_x.h
@@ -0,0 +1,5 @@
1#ifndef E_EV_X_H
2#define E_EV_X_H 1
3void e_ev_x_init(void);
4char *e_key_press_translate_into_typeable(Ev_Key_Down * e);
5#endif
diff --git a/legacy/ecore/src/e_events.c b/legacy/ecore/src/e_events.c
new file mode 100644
index 0000000000..1c52ec428a
--- /dev/null
+++ b/legacy/ecore/src/e_events.c
@@ -0,0 +1,404 @@
1#include "e_events.h"
2#include "e_ev_filter.h"
3#include "e_str.h"
4#include "e_mem.h"
5#include "e_util.h"
6#include "e_ev_signal.h"
7#include <Edb.h>
8#include <errno.h>
9
10/* glocal (yes global/local) variabels for events */
11Ev_Fd_Handler *fd_handlers = NULL;
12Ev_Ipc_Handler *ipc_handlers = NULL;
13Ev_Pid_Handler *pid_handlers = NULL;
14Ev_Timer *timers = NULL;
15
16Eevent *events = NULL;
17Eevent *last_event = NULL;
18
19/* local functions for event handling */
20static void e_handle_event_timer(void);
21static void e_handle_zero_event_timer(void);
22
23/* public functions */
24
25/* add an event to the end of the event queue */
26void
27e_add_event(Eevent_Type type, void *event, void (*ev_free) (void *event))
28{
29 Eevent *ev;
30
31 ev = NEW(Eevent, 1);
32 ev->type = type;
33 ev->ignore = 0;
34 ev->event = event;
35 ev->next = NULL;
36 ev->ev_free = ev_free;
37 if (!events)
38 events = ev;
39 else
40 last_event->next = ev;
41 last_event = ev;
42}
43
44/* delete an event from the event queue */
45void
46e_del_event(void *event)
47{
48 Eevent *ev, *pev;
49
50 pev = NULL;
51 ev = events;
52 while (ev)
53 {
54 if (ev->event == event)
55 {
56 if (pev)
57 pev->next = ev->next;
58 else
59 events = ev->next;
60 if (!ev->next)
61 last_event = pev;
62 if ((ev->event) && (ev->ev_free))
63 (*ev->ev_free) (ev->event);
64 FREE(ev);
65 return;
66 }
67 pev = ev;
68 ev = ev->next;
69 }
70}
71
72void
73e_del_all_events(void)
74{
75 Eevent *ev, *pev;
76
77 ev = events;
78 while (ev)
79 {
80 pev = ev;
81 ev = ev->next;
82 if ((pev->event) && (pev->ev_free))
83 pev->ev_free(pev->event);
84 FREE(pev);
85 }
86 events = NULL;
87 last_event = NULL;
88}
89
90Eevent *
91e_get_last_event(void)
92{
93 return last_event;
94}
95
96/* add a callback handler if fd is active for reading */
97void
98e_add_event_fd(int fd, void (*func) (int fd))
99{
100 Ev_Fd_Handler *fd_h;
101
102 /* new handler struct */
103 fd_h = NEW(Ev_Fd_Handler, 1);
104 fd_h->next = fd_handlers;
105 fd_h->fd = fd;
106 fd_h->func = func;
107 fd_handlers = fd_h;
108}
109
110/* delete handler for fd */
111void
112e_del_event_fd(int fd)
113{
114 START_LIST_DEL(Ev_Fd_Handler, fd_handlers, (_p->fd == fd));
115 FREE(_p);
116 END_LIST_DEL;
117}
118
119void
120e_add_event_pid(pid_t pid, void (*func) (pid_t pid))
121{
122 Ev_Pid_Handler *pid_h;
123
124 /* delete the old handler */
125 e_del_event_pid(pid);
126 /* new handler struct */
127 pid_h = NEW(Ev_Pid_Handler, 1);
128 pid_h->next = pid_handlers;
129 pid_h->pid = pid;
130 pid_h->func = func;
131 pid_handlers = pid_h;
132}
133
134void
135e_del_event_pid(pid_t pid)
136{
137 START_LIST_DEL(Ev_Pid_Handler, pid_handlers, (_p->pid == pid));
138 FREE(_p);
139 END_LIST_DEL;
140}
141
142void
143e_add_event_ipc(int ipc, void (*func) (int ipc))
144{
145 Ev_Ipc_Handler *ipc_h;
146
147 /* delete the old handler */
148 e_del_event_ipc(ipc);
149 /* new handler struct */
150 ipc_h = NEW(Ev_Ipc_Handler, 1);
151 ipc_h->next = ipc_handlers;
152 ipc_h->ipc = ipc;
153 ipc_h->func = func;
154 ipc_handlers = ipc_h;
155}
156
157void
158e_del_event_ipc(int ipc)
159{
160 START_LIST_DEL(Ev_Ipc_Handler, ipc_handlers, (_p->ipc == ipc));
161 FREE(_p);
162 END_LIST_DEL;
163}
164
165/* sit in this loop forever and process events */
166void
167e_event_loop(void)
168{
169 int count, fdsize, timed_out, were_events;
170 double time1, time2, prev_time = 0.0;
171 struct timeval tval;
172 fd_set fdset;
173 Ev_Fd_Handler *fd_h;
174 Ev_Pid_Handler *pid_h;
175 Ev_Ipc_Handler *ipc_h;
176
177 /* init some of the time variables */
178 time1 = e_get_time();
179 time2 = time1 - prev_time;
180 prev_time = time1;
181 for (;;)
182 {
183 /* state setup */
184 timed_out = 0;
185 were_events = 0;
186
187 /* setup fd array from list of listening fd's */
188 fdsize = 0;
189 FD_ZERO(&fdset);
190 /* for ever fd handler add the fd to the array and incriment fdsize */
191 for (fd_h = fd_handlers; fd_h; fd_h = fd_h->next)
192 {
193 FD_SET(fd_h->fd, &fdset);
194 if (fd_h->fd > fdsize)
195 fdsize = fd_h->fd;
196 }
197 count = 1;
198 /* if there are timers setup adjust timeout value and select */
199 if (timers)
200 {
201 if (timers->just_added)
202 {
203 timers->just_added = 0;
204 time1 = timers->in;
205 }
206 else
207 {
208 time1 = timers->in - time2;
209 if (time1 < 0.0)
210 time1 = 0.0;
211 timers->in = time1;
212 }
213 tval.tv_sec = (long)time1;
214 tval.tv_usec = (long)((time1 - ((double)tval.tv_sec)) * 1000000);
215 if (tval.tv_sec < 0)
216 tval.tv_sec = 0;
217 if (tval.tv_usec <= 1000)
218 tval.tv_usec = 1000;
219 e_handle_zero_event_timer();
220 if ((!e_events_pending()) &&
221 (!e_ev_signal_events_pending()))
222 count = select(fdsize + 1, &fdset, NULL, NULL, &tval);
223 }
224 /* no timers - just sit and block */
225 else
226 {
227 if (e_db_runtime_flush())
228 {
229 if ((!e_events_pending()) &&
230 (!e_ev_signal_events_pending()))
231 count = select(fdsize + 1, &fdset, NULL, NULL, NULL);
232 }
233 else
234 {
235 tval.tv_sec = 1;
236 tval.tv_usec = 0;
237 if ((!e_events_pending()) &&
238 (!e_ev_signal_events_pending()))
239 count = select(fdsize + 1, &fdset, NULL, NULL, &tval);
240 }
241 }
242 for (pid_h = pid_handlers; pid_h; pid_h = pid_h->next)
243 pid_h->func(pid_h->pid);
244 for (ipc_h = ipc_handlers; ipc_h; ipc_h = ipc_h->next)
245 ipc_h->func(ipc_h->ipc);
246 /* return < 0 - error or signal interrupt */
247 if (count < 0)
248 {
249 /* error */
250 if ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF))
251 {
252 fprintf(stderr, "EEEEEEEEEEEEEEEEEEEEK\n");
253 exit(1);
254 }
255 }
256 /* timers are available and its a timeout */
257 if ((timers) && (count == 0))
258 {
259 e_handle_event_timer();
260 timed_out = 1;
261 }
262 if (count < 0)
263 count = 0;
264 if (e_events_pending())
265 {
266 count++;
267 FD_SET(e_x_get_fd(), &fdset);
268 }
269 /* fd's are active */
270 if (count > 0)
271 {
272 /* for every fd handler - if its fd si set - call the func */
273 for (fd_h = fd_handlers; fd_h;)
274 {
275 Ev_Fd_Handler *fdh;
276
277 fdh = fd_h;
278 fd_h = fd_h->next;
279 if (FD_ISSET(fdh->fd, &fdset))
280 fdh->func(fdh->fd);
281 }
282 }
283 if (events)
284 e_event_filter(events);
285 if (events)
286 {
287 e_event_filter_events_handle(events);
288 were_events = 1;
289 }
290 e_del_all_events();
291 if ((timed_out) || (were_events))
292 e_event_filter_idle_handle();
293 e_flush();
294 time1 = e_get_time();
295 time2 = time1 - prev_time;
296 prev_time = time1;
297 }
298}
299
300/* add a timeout funcitont o be called in "in" seconds with name name */
301void
302e_add_event_timer(char *name, double in, void (*func) (int val, void *data),
303 int val, void *data)
304{
305 Ev_Timer *timer, *ptr, *pptr;
306 double tally;
307
308 if (name)
309 e_del_event_timer(name);
310 timer = NEW(Ev_Timer, 1);
311 timer->next = NULL;
312 timer->func = func;
313 timer->data = data;
314 timer->val = val;
315 timer->just_added = 1;
316 timer->in = in;
317 timer->name = e_string_dup(name);
318 if (!timers)
319 timers = timer;
320 else
321 {
322 pptr = NULL;
323 ptr = timers;
324 tally = 0.0;
325 while (ptr)
326 {
327 tally += ptr->in;
328 if (tally > in)
329 {
330 tally -= ptr->in;
331 timer->next = ptr;
332 if (pptr)
333 pptr->next = timer;
334 else
335 timers = timer;
336 timer->in -= tally;
337 if (timer->next)
338 timer->next->in -= timer->in;
339 return;
340 }
341 pptr = ptr;
342 ptr = ptr->next;
343 }
344 if (pptr)
345 pptr->next = timer;
346 else
347 timers = timer;
348 timer->in -= tally;
349 }
350}
351
352/* delete a timer timeout entry named "name" */
353void *
354e_del_event_timer(char *name)
355{
356 Ev_Timer *timer, *ptr, *pptr;
357
358 pptr = NULL;
359 ptr = timers;
360 while (ptr)
361 {
362 timer = ptr;
363 if (e_string_cmp(timer->name, name))
364 {
365 void *data;
366
367 if (pptr)
368 pptr->next = timer->next;
369 else
370 timers = timer->next;
371 if (timer->next)
372 timer->next->in += timer->in;
373 IF_FREE(timer->name);
374 data = timer->data;
375 FREE(timer);
376 return data;
377 }
378 pptr = ptr;
379 ptr = ptr->next;
380 }
381 return NULL;
382}
383
384/* private functions */
385static void
386e_handle_event_timer(void)
387{
388 Ev_Timer *timer;
389
390 if (!timers)
391 return;
392 timer = timers;
393 timers = timer->next;
394 (*(timer->func)) (timer->val, timer->data);
395 IF_FREE(timer->name);
396 FREE(timer);
397}
398
399static void
400e_handle_zero_event_timer(void)
401{
402 while ((timers) && (timers->in == 0.0))
403 e_handle_event_timer();
404}
diff --git a/legacy/ecore/src/e_events.h b/legacy/ecore/src/e_events.h
new file mode 100644
index 0000000000..b5950e457f
--- /dev/null
+++ b/legacy/ecore/src/e_events.h
@@ -0,0 +1,430 @@
1#ifndef E_EVENTS_H
2#define E_EVENTS_H 1
3
4#include <stdio.h>
5#include <signal.h>
6#include <sys/types.h>
7#include "e_x.h"
8
9typedef struct _eev Eevent;
10typedef struct _ev_fd_handler Ev_Fd_Handler;
11typedef struct _ev_pid_handler Ev_Pid_Handler;
12typedef struct _ev_ipc_handler Ev_Ipc_Handler;
13typedef struct _ev_timer Ev_Timer;
14
15typedef struct _ev_key_down Ev_Key_Down;
16typedef struct _ev_key_up Ev_Key_Up;
17typedef struct _ev_mouse_down Ev_Mouse_Down;
18typedef struct _ev_mouse_up Ev_Mouse_Up;
19typedef struct _ev_wheel Ev_Wheel;
20typedef struct _ev_mouse_move Ev_Mouse_Move;
21typedef struct _ev_window_enter Ev_Window_Enter;
22typedef struct _ev_window_leave Ev_Window_Leave;
23typedef struct _ev_window_focus_in Ev_Window_Focus_In;
24typedef struct _ev_window_focus_out Ev_Window_Focus_Out;
25typedef struct _ev_window_expose Ev_Window_Expose;
26typedef struct _ev_window_visibility Ev_Window_Visibility;
27typedef struct _ev_window_create Ev_Window_Create;
28typedef struct _ev_window_destroy Ev_Window_Destroy;
29typedef struct _ev_window_map Ev_Window_Map;
30typedef struct _ev_window_unmap Ev_Window_Unmap;
31typedef struct _ev_window_map_request Ev_Window_Map_Request;
32typedef struct _ev_window_reparent Ev_Window_Reparent;
33typedef struct _ev_window_configure Ev_Window_Configure;
34typedef struct _ev_window_configure_request Ev_Window_Configure_Request;
35typedef struct _ev_window_circulate Ev_Window_Circulate;
36typedef struct _ev_window_circulate_request Ev_Window_Circulate_Request;
37typedef struct _ev_window_property Ev_Window_Property;
38typedef struct _ev_window_shape Ev_Window_Shape;
39typedef struct _ev_client_message Ev_Message;
40typedef struct _ev_colormap Ev_Colormap;
41typedef struct _ev_window_delete Ev_Window_Delete;
42typedef struct _ev_child Ev_Child;
43typedef struct _ev_user Ev_User;
44typedef struct _ev_file_progress Ev_File_Progress;
45typedef struct _ev_file_update Ev_File_Update;
46typedef struct _ev_dnd_drop_request Ev_Dnd_Drop_Request;
47typedef struct _ev_dnd_drop_end Ev_Dnd_Drop_End;
48typedef struct _ev_dnd_drop_position Ev_Dnd_Drop_Position;
49typedef struct _ev_dnd_drop Ev_Dnd_Drop;
50typedef struct _ev_dnd_drop_status Ev_Dnd_Drop_Status;
51typedef struct _ev_dnd_data_request Ev_Dnd_Data_Request;
52
53enum _eev_stack_detail
54{
55 EV_STACK_ABOVE = Above,
56 EV_STACK_BELOW = Below,
57 EV_STACK_TOP_IF = TopIf,
58 EV_STACK_BOTTOM_IF = BottomIf,
59 EV_STACK_OPPOSITE = Opposite
60};
61
62enum _eev_value_mask
63{
64 EV_VALUE_X = CWX,
65 EV_VALUE_Y = CWY,
66 EV_VALUE_W = CWWidth,
67 EV_VALUE_H = CWHeight,
68 EV_VALUE_BORDER = CWBorderWidth,
69 EV_VALUE_SIBLING = CWSibling,
70 EV_VALUE_STACKING = CWStackMode
71};
72
73enum _eev_type
74{
75 EV_MOUSE_MOVE,
76 EV_MOUSE_DOWN,
77 EV_MOUSE_UP,
78 EV_MOUSE_IN,
79 EV_MOUSE_OUT,
80 EV_MOUSE_WHEEL,
81 EV_KEY_DOWN,
82 EV_KEY_UP,
83 EV_WINDOW_MAP,
84 EV_WINDOW_UNMAP,
85 EV_WINDOW_CREATE,
86 EV_WINDOW_DESTROY,
87 EV_WINDOW_CONFIGURE,
88 EV_WINDOW_CONFIGURE_REQUEST,
89 EV_WINDOW_MAP_REQUEST,
90 EV_WINDOW_PROPERTY,
91 EV_WINDOW_CIRCULATE,
92 EV_WINDOW_CIRCULATE_REQUEST,
93 EV_WINDOW_REPARENT,
94 EV_WINDOW_EXPOSE,
95 EV_WINDOW_VISIBILITY,
96 EV_WINDOW_SHAPE,
97 EV_WINDOW_FOCUS_IN,
98 EV_WINDOW_FOCUS_OUT,
99 EV_MESSAGE,
100 EV_WINDOW_DELETE,
101 EV_COLORMAP,
102
103 EV_DND_DROP_REQUEST,
104 EV_DND_DROP_END,
105 EV_DND_DROP_POSITION,
106 EV_DND_DROP,
107 EV_DND_DROP_STATUS,
108 EV_DND_DATA_REQUEST,
109
110 EV_CHILD,
111 EV_USER,
112
113 EV_MAX
114};
115
116typedef enum _eev_type Eevent_Type;
117typedef enum _eev_stack_detail Ev_Stack_Detail;
118typedef enum _eev_value_mask Ev_Confgure_Value_Mask;
119
120struct _eev
121{
122 Eevent_Type type;
123 char ignore;
124 void *event;
125 void (*ev_free) (void *evnt);
126 Eevent *next;
127};
128
129struct _ev_fd_handler
130{
131 int fd;
132 void (*func) (int fd);
133 Ev_Fd_Handler *next;
134};
135
136struct _ev_pid_handler
137{
138 pid_t pid;
139 void (*func) (pid_t pid);
140 Ev_Pid_Handler *next;
141};
142
143struct _ev_ipc_handler
144{
145 int ipc;
146 void (*func) (int ipc);
147 Ev_Ipc_Handler *next;
148};
149
150struct _ev_timer
151{
152 char *name;
153 void (*func) (int val, void *data);
154 int val;
155 void *data;
156 double in;
157 char just_added;
158 Ev_Timer *next;
159};
160
161struct _ev_key_down
162{
163 Window win, root;
164 Ev_Key_Modifiers mods;
165 char *key;
166 char *compose;
167 Time time;
168};
169
170struct _ev_key_up
171{
172 Window win, root;
173 Ev_Key_Modifiers mods;
174 char *key;
175 char *compose;
176 Time time;
177};
178
179struct _ev_mouse_down
180{
181 Window win, root;
182 Ev_Key_Modifiers mods;
183 int button;
184 int x, y;
185 int rx, ry;
186 int double_click, triple_click;
187 Time time;
188};
189
190struct _ev_mouse_up
191{
192 Window win, root;
193 Ev_Key_Modifiers mods;
194 int button;
195 int x, y;
196 int rx, ry;
197 Time time;
198};
199
200struct _ev_wheel
201{
202 Window win, root;
203 Ev_Key_Modifiers mods;
204 int x, y, z;
205 int rx, ry;
206 Time time;
207};
208
209struct _ev_mouse_move
210{
211 Window win, root;
212 Ev_Key_Modifiers mods;
213 int x, y;
214 int rx, ry;
215 Time time;
216};
217
218struct _ev_window_enter
219{
220 Window win, root;
221 int x, y;
222 int rx, ry;
223 Ev_Key_Modifiers mods;
224 Time time;
225};
226
227struct _ev_window_leave
228{
229 Window win, root;
230 int x, y;
231 int rx, ry;
232 Ev_Key_Modifiers mods;
233 Time time;
234};
235
236struct _ev_window_focus_in
237{
238 Window win, root;
239 Time time;
240};
241
242struct _ev_window_focus_out
243{
244 Window win, root;
245 Time time;
246};
247
248struct _ev_window_expose
249{
250 Window win, root;
251 int x, y, w, h;
252};
253
254struct _ev_window_visibility
255{
256 Window win, root;
257 int fully_obscured;
258};
259
260struct _ev_window_create
261{
262 Window win, root;
263 int override;
264};
265
266struct _ev_window_destroy
267{
268 Window win, root;
269};
270
271struct _ev_window_map
272{
273 Window win, root;
274};
275
276struct _ev_window_unmap
277{
278 Window win, root;
279};
280
281struct _ev_window_map_request
282{
283 Window win, root;
284};
285
286struct _ev_window_reparent
287{
288 Window win, root;
289 Window parent_from, parent;
290};
291
292struct _ev_window_configure
293{
294 Window win, root;
295 int x, y, w, h;
296 int wm_generated;
297};
298
299struct _ev_window_configure_request
300{
301 Window win, root;
302 int x, y, w, h;
303 int border;
304 Window stack_win;
305 Ev_Stack_Detail detail;
306 Ev_Confgure_Value_Mask mask;
307};
308
309struct _ev_window_circulate
310{
311 Window win, root;
312 int lower;
313};
314
315struct _ev_window_circulate_request
316{
317 Window win, root;
318 int lower;
319};
320
321struct _ev_window_property
322{
323 Window win, root;
324 Atom atom;
325 Time time;
326};
327
328struct _ev_window_shape
329{
330 Window win, root;
331 Time time;
332};
333
334struct _ev_client_message
335{
336 Window win;
337 int format;
338 Atom atom;
339 union
340 {
341 char b[20];
342 short s[10];
343 long l[5];
344 }
345 data;
346};
347
348struct _ev_colormap
349{
350 Window win, root;
351 Colormap cmap;
352 int installed;
353};
354
355struct _ev_window_delete
356{
357 Window win, root;
358};
359
360struct _ev_dnd_drop_request
361{
362 Window win, root, source_win;
363 int num_files;
364 char **files;
365 int copy, link, move;
366};
367
368struct _ev_dnd_drop_end
369{
370 Window win, root, source_win;
371};
372
373struct _ev_dnd_drop_position
374{
375 Window win, root, source_win;
376 int x, y;
377};
378
379struct _ev_dnd_drop
380{
381 Window win, root, source_win;
382};
383
384struct _ev_dnd_drop_status
385{
386 Window win, root, source_win;
387 int x, y, w, h;
388 int ok;
389};
390
391struct _ev_dnd_data_request
392{
393 Window win, root, source_win;
394 int plain_text;
395 Atom destination_atom;
396};
397
398struct _ev_child
399{
400 pid_t pid;
401 int exit_code;
402};
403
404struct _ev_user
405{
406 int num;
407 int hup;
408};
409
410void e_add_event(Eevent_Type type, void *event,
411 void (*ev_free) (void *event));
412void e_del_event(void *event);
413void e_del_all_events(void);
414Eevent *e_get_last_event(void);
415
416void e_add_event_fd(int fd, void (*func) (int fd));
417void e_del_event_fd(int fd);
418void e_add_event_pid(pid_t pid, void (*func) (pid_t pid));
419void e_del_event_pid(pid_t pid);
420void e_add_event_ipc(int ipc, void (*func) (int ipc));
421void e_del_event_ipc(int ipc);
422
423void e_event_loop(void);
424
425void e_add_event_timer(char *name, double in,
426 void (*func) (int val, void *data),
427 int val, void *data);
428void *e_del_event_timer(char *name);
429
430#endif
diff --git a/legacy/ecore/src/e_mem.c b/legacy/ecore/src/e_mem.c
new file mode 100644
index 0000000000..448525eb26
--- /dev/null
+++ b/legacy/ecore/src/e_mem.c
@@ -0,0 +1 @@
#include "e_mem.h"
diff --git a/legacy/ecore/src/e_mem.h b/legacy/ecore/src/e_mem.h
new file mode 100644
index 0000000000..82253d7bb8
--- /dev/null
+++ b/legacy/ecore/src/e_mem.h
@@ -0,0 +1,60 @@
1#ifndef E_MEM_H
2#define E_MEM_H 1
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7
8#define MEMCPY(src, dst, type, num) memcpy(dst, src, sizeof(type) * (num))
9
10#if 1
11#define NEW(dat, num) malloc(sizeof(dat) * (num))
12#define NEW_PTR(num) malloc(sizeof(void *) * (num))
13#define FREE(dat) {if (dat) {free(dat); dat = NULL;} else {printf("eek - NULL free\n");sleep(30);}}
14#define IF_FREE(dat) {if (dat) FREE(dat);}
15#define REALLOC(dat, type, num) {if (dat) dat = realloc(dat, sizeof(type) * (num)); else dat = malloc(sizeof(type) * (num));}
16#define REALLOC_PTR(dat, num) {if (dat) dat = realloc(dat, sizeof(void *) * (num)); else dat = malloc(sizeof(void *) * (num));}
17
18#else
19static void *
20_NEW(int size, int num)
21{
22 void *dat;
23
24 dat = malloc(size * num);
25 printf("NEW(%i) = %p\n", size * num, dat);
26 return dat;
27}
28static void *
29_NEW_PTR(int num)
30{
31 void *dat;
32
33 dat = malloc(sizeof(void *) * num);
34 printf("NEW(%i) = %p\n", sizeof(void *) * num, dat);
35
36 return dat;
37}
38static void
39_IF_FREE(void *dat)
40{
41 printf("IF_FREE(%p)\n", dat);
42 if (dat)
43 free(dat);
44}
45static void
46_FREE(void *dat)
47{
48 printf("FREE(%p)\n", dat);
49 free(dat);
50}
51#define NEW(dat, num) _NEW(sizeof(dat), (num))
52#define NEW_PTR(num) _NEW(sizeof(void *), (num))
53#define IF_FREE(dat) {_IF_FREE(dat);}
54#define FREE(dat) {_FREE(dat);}
55
56#define REALLOC(dat, type, num) {dat = realloc(dat, sizeof(type) * (num)); printf("REALLOC(%i) = %p\n", sizeof(type) * (num), dat);}
57#define REALLOC_PTR(dat, num) {dat = realloc(dat, sizeof(void *) * (num)); printf("REALLOC_PTR(%i) = %p\n", sizeof(void *) * (num), dat);}
58
59#endif
60#endif
diff --git a/legacy/ecore/src/e_str.c b/legacy/ecore/src/e_str.c
new file mode 100644
index 0000000000..16d570ffc6
--- /dev/null
+++ b/legacy/ecore/src/e_str.c
@@ -0,0 +1,151 @@
1#include "e_str.h"
2#include "e_mem.h"
3
4/* string manipulation conveience calls */
5
6void
7e_string_free_list(char **slist, int num)
8{
9 int i;
10
11 for (i = 0; i < num; i++)
12 FREE(slist[i]);
13 FREE(slist);
14}
15
16char *
17e_string_dup(char *str)
18{
19 if (!str)
20 return NULL;
21 return strdup(str);
22}
23
24int
25e_string_cmp(char *s1, char *s2)
26{
27 if ((!s1) || (!s2))
28 return 0;
29 if (!strcmp(s1, s2))
30 return 1;
31 return 0;
32}
33
34int
35e_string_case_cmp(char *s1, char *s2)
36{
37 if ((!s1) || (!s2))
38 return 0;
39 if (!strcasecmp(s1, s2))
40 return 1;
41 return 0;
42}
43
44int
45e_string_length(char *str)
46{
47 return strlen(str);
48}
49
50void
51e_string_clear(char *str)
52{
53 str[0] = 0;
54}
55
56void
57e_string_cat(char *str, char *cat)
58{
59 strcat(str, cat);
60}
61
62void
63e_string_cat_n(char *str, char *cat, int start, int len)
64{
65 strncat(str, &(cat[start]), len);
66}
67
68char *
69e_string_escape(char *str)
70{
71 char buf[8192];
72 int i, j, len;
73
74 e_string_clear(buf);
75 len = e_string_length(str);
76 for (i = 0, j = 0; i < len; i++)
77 {
78 switch (str[i])
79 {
80 case ' ':
81 case '"':
82 case '\'':
83 case '\\':
84 case '(':
85 case ')':
86 case '[':
87 case ']':
88 case '$':
89 case '`':
90 case '~':
91 case '!':
92 case '#':
93 case '&':
94 case '*':
95 case '?':
96 case '|':
97 case ';':
98 case '<':
99 case '>':
100 buf[j++] = '\\';
101 buf[j++] = str[i];
102 break;
103 default:
104 buf[j++] = str[i];
105 break;
106 }
107 }
108 buf[j] = 0;
109 return e_string_dup(buf);
110}
111
112char *
113e_string_build(char *format, char **rep_list, int rep_num)
114{
115 char buf[16384], *s;
116 int i;
117
118 e_string_clear(buf);
119 s = format;
120 i = 0;
121 while (*s)
122 {
123 if (s[0] == '%')
124 {
125 if (s[1] == '%')
126 e_string_cat(buf, "%");
127 else
128 {
129 int j;
130
131 for (j = 0; j < rep_num; j += 2)
132 {
133 if (s[1] == rep_list[j][0])
134 {
135 char *ss;
136
137 ss = e_string_escape(rep_list[j + 1]);
138 e_string_cat(buf, ss);
139 FREE(ss);
140 break;
141 }
142 }
143 }
144 s++;
145 }
146 else
147 strncat(buf, s, 1);
148 s++;
149 }
150 return e_string_dup(buf);
151}
diff --git a/legacy/ecore/src/e_str.h b/legacy/ecore/src/e_str.h
new file mode 100644
index 0000000000..3769301e52
--- /dev/null
+++ b/legacy/ecore/src/e_str.h
@@ -0,0 +1,18 @@
1#ifndef E_STR_H
2#define E_STR_H 1
3
4#include <stdio.h>
5#include <string.h>
6
7void e_string_free_list(char **slist, int num);
8char *e_string_dup(char *str);
9int e_string_cmp(char *s1, char *s2);
10int e_string_case_cmp(char *s1, char *s2);
11int e_string_length(char *str);
12void e_string_clear(char *str);
13void e_string_cat(char *str, char *cat);
14void e_string_cat_n(char *str, char *cat, int start, int len);
15char *e_string_escape(char *str);
16char *e_string_build(char *format, char **rep_list, int rep_num);
17
18#endif
diff --git a/legacy/ecore/src/e_util.c b/legacy/ecore/src/e_util.c
new file mode 100644
index 0000000000..eda5583438
--- /dev/null
+++ b/legacy/ecore/src/e_util.c
@@ -0,0 +1,164 @@
1#include "e_util.h"
2#include "e_mem.h"
3#include "e_str.h"
4
5static void sort_alpha_internal(char **a, int l, int r);
6
7double
8e_get_time(void)
9{
10 struct timeval timev;
11
12 gettimeofday(&timev, NULL);
13 return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
14}
15
16pid_t
17e_run(char *exe)
18{
19 pid_t pid;
20
21 pid = fork();
22 if (pid)
23 return pid;
24 setsid();
25 execl("/bin/sh", "/bin/sh", "-c", exe, NULL);
26 exit(0);
27 return 0;
28}
29
30pid_t
31e_run_in_dir(char *exe, char *dir)
32{
33 pid_t pid;
34
35 pid = fork();
36 if (pid)
37 return pid;
38 chdir(dir);
39 setsid();
40 execl("/bin/sh", "/bin/sh", "-c", exe, NULL);
41 exit(0);
42 return 0;
43}
44
45void
46e_set_env(char *variable, char *content)
47{
48 char env[4096];
49
50 sprintf(env, "%s=%s", variable, content);
51 putenv(env);
52}
53
54uid_t
55e_user_id(void)
56{
57 static uid_t uid = 0xffffffff;
58
59 if (uid != 0xffffffff)
60 return uid;
61 uid = getuid();
62 return uid;
63}
64
65gid_t
66e_group_id(void)
67{
68 static gid_t gid = 0xffffffff;
69
70 if (gid != 0xffffffff)
71 return gid;
72 gid = getgid();
73 return gid;
74}
75
76static void
77sort_alpha_internal(char **a, int l, int r)
78{
79 int i, j, m;
80 char *v, *t;
81
82 if (r > l)
83 {
84 m = ((r + l) >> 1) + 1;
85 if (strcmp(a[l], a[r]) > 0)
86 {
87 t = a[l];
88 a[l] = a[r];
89 a[r] = t;
90 }
91 if (strcmp(a[l], a[m]) > 0)
92 {
93 t = a[l];
94 a[l] = a[m];
95 a[m] = t;
96 }
97 if (strcmp(a[r], a[m]) > 0)
98 {
99 t = a[r];
100 a[r] = a[m];
101 a[m] = t;
102 }
103 v = a[r];
104 i = l - 1;
105 j = r;
106 for (;;)
107 {
108 while (strcmp(a[++i], v) < 0);
109 while (strcmp(a[--j], v) > 0);
110 if (i >= j)
111 break;
112 t = a[i];
113 a[i] = a[j];
114 a[j] = t;
115 }
116 t = a[i];
117 a[i] = a[r];
118 a[r] = t;
119 sort_alpha_internal(a, l, i - 1);
120 sort_alpha_internal(a, i + 1, r);
121 }
122}
123
124void
125sort_alpha(char **list, int num)
126{
127 sort_alpha_internal(list, 0, num - 1);
128}
129
130char *
131e_home_dir(void)
132{
133 char *home;
134
135 home = getenv("HOME");
136 if (!home)
137 home = getenv("TMPDIR");
138 if (!home)
139 home = "/tmp";
140 return home;
141}
142
143const char *
144e_get_basename(const char *s)
145{
146 const char *b;
147
148 b = strrchr(s, '/');
149 return ((b) ? (++b) : (s));
150}
151
152void
153spawn_info_window(char *path)
154{
155
156 char runline[8192];
157 char *realline;
158
159 realline = e_string_escape(path);
160 sprintf(runline, "efileinfo %s", realline);
161 e_run(runline);
162 IF_FREE(realline);
163
164}
diff --git a/legacy/ecore/src/e_util.h b/legacy/ecore/src/e_util.h
new file mode 100644
index 0000000000..4e688605a2
--- /dev/null
+++ b/legacy/ecore/src/e_util.h
@@ -0,0 +1,56 @@
1#ifndef E_UTIL_H
2#define E_UTIL_H 1
3
4#include <stdio.h>
5#include <sys/time.h>
6#include <sys/types.h>
7#include <unistd.h>
8
9#ifdef EFM_DEBUG
10# define D(x) do {printf(__FILE__ ":%d: ", __LINE__); printf x; fflush(stdout);} while (0)
11#else
12# define D(x) ((void) 0)
13#endif
14
15#define XY_IN_RECT(x, y, rx, ry, rw, rh) \
16(((x) >= (rx)) && ((y) >= (ry)) && ((x) < ((rx) + (rw))) && ((y) < ((ry) + (rh))))
17#define CLIP(x, y, w, h, xx, yy, ww, hh) \
18if (x < (xx)) {w += (x - (xx)); x = (xx);} \
19if (y < (yy)) {h += (y - (yy)); y = (yy);} \
20if ((x + w) > ((xx) + (ww))) {w = (ww) - x;} \
21if ((y + h) > ((yy) + (hh))) {h = (hh) - y;}
22#define BOUND_RECTS(cx, cy, cw, ch, x, y, w, h, d) \
23if (d) { \
24if ((x) < cx) {cw += (cx - (x)); cx = x;} \
25if ((y) < cy) {ch += (cy - (y)); cy = y;} \
26if (((x) + (w)) > (cx + cw)) cw += (((x) + (w)) - (cx + cw)); \
27if (((y) + (h)) > (cy + ch)) ch += (((y) + (h)) - (cy + ch)); } \
28else { cx = x; cy = y; cw = w; ch = h; (d) = 1; }
29#define MIN(a, b) (((a) < (b)) ? (a) : (b))
30#define MAX(a, b) (((a) > (b)) ? (a) : (b))
31#define SPANS_COMMON(x1, w1, x2, w2) \
32(!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
33#define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
34((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
35#define RECT_INSIDE(x, y, w, h, xx, yy, ww, hh) \
36(((xx) >= (x)) && (((xx) + (ww)) <= ((x) + (w))) && \
37 ((yy) >= (y)) && (((yy) + (hh)) <= ((y) + (h))))
38#define START_LIST_DEL(type, base, cmp) \
39type *_p, *_pp; _pp = NULL; _p = (base); while(_p) { if (cmp) { \
40if (_pp) _pp->next = _p->next; else (base) = _p->next;
41#define END_LIST_DEL \
42return; } _pp = _p; _p = _p->next; }
43#define IC(name) e_path_find(path_icons, name)
44
45double e_get_time(void);
46pid_t e_run(char *exe);
47pid_t e_run_in_dir(char *exe, char *dir);
48void e_set_env(char *variable, char *content);
49uid_t e_user_id(void);
50gid_t e_group_id(void);
51void sort_alpha(char **list, int num);
52char *e_home_dir(void);
53const char *e_get_basename(const char *);
54void spawn_info_window(char *path);
55
56#endif
diff --git a/legacy/ecore/src/e_x.c b/legacy/ecore/src/e_x.c
new file mode 100644
index 0000000000..685b9887df
--- /dev/null
+++ b/legacy/ecore/src/e_x.c
@@ -0,0 +1,2306 @@
1#include "e_x.h"
2#include "e_mem.h"
3#include "e_str.h"
4#include <Imlib2.h>
5#include <stdio.h>
6#include <unistd.h>
7
8typedef struct _window_list Window_List;
9
10struct _window_list
11{
12 Window win;
13 Window_List *next;
14};
15
16static Display *disp;
17static Visual *default_vis;
18static Colormap default_cm;
19static int default_depth;
20static Window default_win;
21static Window default_root;
22
23static XContext xid_context = 0;
24
25static int lock_scroll = 0;
26static int lock_num = 0;
27static int lock_caps = 0;
28
29static Window focused_win = 0;
30
31static int mod_shift = 0;
32static int mod_ctrl = 0;
33static int mod_alt = 0;
34static int mod_win = 0;
35
36static Window grabkey_win = 0;
37
38static int mouse_x = 0, mouse_y = 0;
39
40static Window current_dnd_win = 0;
41static int current_dnd_target_ok = 0;
42
43static int x_grabs = 0;
44
45static Window_List *ignore_wins = NULL;
46
47static Window grab_pointer_win = 0;
48
49static int dnd_copy = 0;
50static int dnd_link = 0;
51static int dnd_move = 1;
52
53static void e_handle_x_error(Display * d, XErrorEvent * ev);
54static void e_handle_x_io_error(Display * d);
55static Window e_window_at_xy_0(Window base, int bx, int by, int x, int y);
56
57static void
58e_handle_x_error(Display * d, XErrorEvent * ev)
59{
60 /* ignroe all X errors */
61 return;
62 d = NULL;
63 ev = NULL;
64}
65
66static void
67e_handle_x_io_error(Display * d)
68{
69 /* FIXME: call clean exit handler */
70 exit(1);
71 d = NULL;
72}
73
74void
75e_del_child(Window win, Window child)
76{
77 E_XID *xid = NULL;
78
79 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
80 return;
81 if (xid)
82 {
83 int i;
84
85 for (i = 0; i < xid->children_num; i++)
86 {
87 if (xid->children[i] == child)
88 {
89 int j;
90
91 for (j = i; j < xid->children_num - 1; j++)
92 xid->children[j] = xid->children[j + 1];
93 xid->children_num--;
94 REALLOC(xid->children, Window, xid->children_num);
95 return;
96 }
97 }
98 }
99}
100
101void
102e_add_child(Window win, Window child)
103{
104 E_XID *xid = NULL;
105
106 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
107 return;
108 if (xid)
109 {
110 xid->children_num++;
111 if (!xid->children)
112 xid->children = NEW(Window, xid->children_num);
113 else
114 REALLOC(xid->children, Window, xid->children_num);
115 xid->children[xid->children_num - 1] = child;
116 }
117}
118
119void
120e_raise_child(Window win, Window child)
121{
122 E_XID *xid = NULL;
123
124 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
125 return;
126 if (xid)
127 {
128 int i;
129
130 for (i = 0; i < xid->children_num; i++)
131 {
132 if (xid->children[i] == child)
133 {
134 int j;
135
136 for (j = i; j < xid->children_num - 1; j++)
137 xid->children[j] = xid->children[j + 1];
138 xid->children[xid->children_num - 1] = child;
139 return;
140 }
141 }
142 }
143}
144
145void
146e_lower_child(Window win, Window child)
147{
148 E_XID *xid = NULL;
149
150 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
151 return;
152 if (xid)
153 {
154 int i;
155
156 for (i = 0; i < xid->children_num; i++)
157 {
158 if (xid->children[i] == child)
159 {
160 int j;
161
162 for (j = i; j > 0; j--)
163 xid->children[j] = xid->children[j - 1];
164 xid->children[0] = child;
165 return;
166 }
167 }
168 }
169}
170
171E_XID *
172e_add_xid(Window win, int x, int y, int w, int h, int depth, Window parent)
173{
174 E_XID *xid = NULL;
175
176 e_window_add_events(win, XEV_IN_OUT | XEV_CONFIGURE | XEV_VISIBILITY);
177 xid = NEW(E_XID, 1);
178 xid->win = win;
179 xid->x = x;
180 xid->y = y;
181 xid->w = w;
182 xid->h = h;
183 xid->mapped = 0;
184 xid->depth = depth;
185 xid->mouse_in = 0;
186 xid->parent = parent;
187 xid->root = e_window_get_root(parent);
188 xid->children_num = 0;
189 xid->children = NULL;
190 XSaveContext(disp, xid->win, xid_context, (XPointer) xid);
191 return xid;
192}
193
194E_XID *
195e_validate_xid(Window win)
196{
197 E_XID *xid = NULL;
198
199 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
200 {
201 XWindowAttributes att;
202 Window root_ret = 0, parent_ret = 0, *children_ret = NULL;
203 unsigned int children_ret_num = 0;
204
205 e_window_add_events(win, XEV_IN_OUT | XEV_CONFIGURE |
206 XEV_VISIBILITY | XEV_CHILD_CHANGE);
207 xid = NEW(E_XID, 1);
208 xid->win = win;
209 if (!XGetWindowAttributes(disp, win, &att))
210 {
211 FREE(xid);
212 return NULL;
213 }
214 if (!XQueryTree(disp, win, &root_ret, &parent_ret, &children_ret,
215 &children_ret_num))
216 {
217 FREE(xid);
218 return NULL;
219 }
220 xid->parent = parent_ret;
221 if (xid->parent)
222 e_validate_xid(xid->parent);
223 if (children_ret)
224 {
225 xid->children_num = children_ret_num;
226 xid->children = NEW(Window, children_ret_num);
227 MEMCPY(children_ret, xid->children, Window, children_ret_num);
228 XFree(children_ret);
229 }
230 else
231 {
232 xid->children_num = 0;
233 xid->children = NULL;
234 }
235 xid->root = root_ret;
236 xid->x = att.x;
237 xid->y = att.y;
238 xid->w = att.width;
239 xid->h = att.height;
240 if (att.map_state == IsUnmapped)
241 xid->mapped = 0;
242 else
243 xid->mapped = 1;
244 xid->depth = att.depth;
245 xid->mouse_in = 0;
246 XSaveContext(disp, xid->win, xid_context, (XPointer) xid);
247 }
248 return xid;
249}
250
251void
252e_unvalidate_xid(Window win)
253{
254 E_XID *xid = NULL;
255
256 if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT)
257 return;
258 if (xid)
259 {
260 int i;
261
262 for (i = 0; i < xid->children_num; i++)
263 e_unvalidate_xid(xid->children[i]);
264 IF_FREE(xid->children);
265 FREE(xid);
266 XDeleteContext(disp, win, xid_context);
267 }
268}
269
270void
271e_sync(void)
272{
273 XSync(disp, False);
274}
275
276void
277e_flush(void)
278{
279 XFlush(disp);
280}
281
282Window
283e_window_new(Window parent, int x, int y, int w, int h)
284{
285 Window win;
286 XSetWindowAttributes attr;
287
288 if (!parent)
289 parent = default_root;
290 attr.backing_store = NotUseful;
291 attr.override_redirect = False;
292 attr.colormap = default_cm;
293 attr.border_pixel = 0;
294 attr.background_pixmap = None;
295 attr.save_under = False;
296 attr.do_not_propagate_mask = True;
297 win = XCreateWindow(disp, parent,
298 x, y, w, h, 0,
299 default_depth, InputOutput, default_vis,
300 CWOverrideRedirect | CWSaveUnder | CWBackingStore |
301 CWColormap | CWBackPixmap | CWBorderPixel |
302 CWDontPropagate, &attr);
303 e_add_xid(win, x, y, w, h, default_depth, parent);
304 return win;
305}
306
307Window
308e_window_override_new(Window parent, int x, int y, int w, int h)
309{
310 Window win;
311 XSetWindowAttributes attr;
312
313 if (!parent)
314 parent = default_root;
315 attr.backing_store = NotUseful;
316 attr.override_redirect = True;
317 attr.colormap = default_cm;
318 attr.border_pixel = 0;
319 attr.background_pixmap = None;
320 attr.save_under = False;
321 attr.do_not_propagate_mask = True;
322 win = XCreateWindow(disp, parent,
323 x, y, w, h, 0,
324 default_depth, InputOutput, default_vis,
325 CWOverrideRedirect | CWSaveUnder | CWBackingStore |
326 CWColormap | CWBackPixmap | CWBorderPixel |
327 CWDontPropagate, &attr);
328 e_add_xid(win, x, y, w, h, default_depth, parent);
329 return win;
330}
331
332Window
333e_window_input_new(Window parent, int x, int y, int w, int h)
334{
335 Window win;
336 XSetWindowAttributes attr;
337
338 if (!parent)
339 parent = default_root;
340 attr.override_redirect = True;
341 attr.do_not_propagate_mask = True;
342 win = XCreateWindow(disp, parent,
343 x, y, w, h, 0,
344 0, InputOnly, default_vis,
345 CWOverrideRedirect | CWDontPropagate, &attr);
346 e_add_xid(win, x, y, w, h, 0, parent);
347 return win;
348}
349
350void
351e_window_show(Window win)
352{
353 E_XID *xid = NULL;
354
355 xid = e_validate_xid(win);
356 if (xid)
357 {
358 if (xid->mapped)
359 xid->mapped = 1;
360 XMapWindow(disp, win);
361 }
362}
363
364void
365e_window_hide(Window win)
366{
367 E_XID *xid = NULL;
368
369 xid = e_validate_xid(win);
370 if (xid)
371 {
372 if (!xid->mapped)
373 return;
374 xid->mapped = 0;
375 XUnmapWindow(disp, win);
376 }
377}
378
379Pixmap
380e_pixmap_new(Window win, int w, int h, int dep)
381{
382 if (!win)
383 win = default_win;
384 if (dep == 0)
385 dep = default_depth;
386 return XCreatePixmap(disp, win, w, h, dep);
387}
388
389void
390e_pixmap_free(Pixmap pmap)
391{
392 if (!pmap)
393 return;
394 XFreePixmap(disp, pmap);
395}
396
397void
398e_window_set_background_pixmap(Window win, Pixmap pmap)
399{
400 XSetWindowBackgroundPixmap(disp, win, pmap);
401}
402
403void
404e_window_set_shape_mask(Window win, Pixmap mask)
405{
406 XShapeCombineMask(disp, win, ShapeBounding, 0, 0, mask, ShapeSet);
407}
408
409void
410e_window_clear(Window win)
411{
412 XClearWindow(disp, win);
413}
414
415void
416e_window_clear_area(Window win, int x, int y, int w, int h)
417{
418 XClearArea(disp, win, x, y, w, h, False);
419}
420
421void
422e_pointer_xy(Window win, int *x, int *y)
423{
424 Window dw;
425 unsigned int dm;
426 int wx, wy;
427
428 if (win == 0)
429 win = default_root;
430 XQueryPointer(disp, win, &dw, &dw, &mouse_x, &mouse_y, &wx, &wy, &dm);
431 if (x)
432 *x = wx;
433 if (y)
434 *y = wy;
435}
436
437void
438e_pointer_xy_set(int x, int y)
439{
440 mouse_x = x;
441 mouse_y = y;
442}
443
444void
445e_pointer_xy_get(int *x, int *y)
446{
447 if (x)
448 *x = mouse_x;
449 if (y)
450 *y = mouse_y;
451}
452
453void
454e_window_set_events(Window win, long mask)
455{
456 if (win == 0)
457 win = default_root;
458 XSelectInput(disp, win, mask);
459}
460
461void
462e_window_remove_events(Window win, long mask)
463{
464 XWindowAttributes att;
465
466 if (win == 0)
467 win = default_root;
468 if (XGetWindowAttributes(disp, win, &att) == True)
469 {
470 mask = att.your_event_mask & (~mask);
471 e_window_set_events(win, mask);
472 }
473}
474
475void
476e_window_add_events(Window win, long mask)
477{
478 XWindowAttributes att;
479
480 if (win == 0)
481 win = default_root;
482 if (XGetWindowAttributes(disp, win, &att) == True)
483 {
484 mask = att.your_event_mask | mask;
485 e_window_set_events(win, mask);
486 }
487}
488
489void
490e_window_move(Window win, int x, int y)
491{
492 E_XID *xid = NULL;
493
494 xid = e_validate_xid(win);
495 if (xid)
496 {
497 if ((xid->x == x) && (xid->y == y))
498 return;
499 xid->x = x;
500 xid->y = y;
501 XMoveWindow(disp, win, x, y);
502 }
503}
504
505void
506e_window_resize(Window win, int w, int h)
507{
508 E_XID *xid = NULL;
509
510 xid = e_validate_xid(win);
511 if (xid)
512 {
513 if ((xid->w == w) && (xid->h == h))
514 return;
515 xid->w = w;
516 xid->h = h;
517 XResizeWindow(disp, win, w, h);
518 }
519}
520
521void
522e_window_move_resize(Window win, int x, int y, int w, int h)
523{
524 E_XID *xid = NULL;
525
526 xid = e_validate_xid(win);
527 if (xid)
528 {
529 if ((xid->x == x) && (xid->y == y) && (xid->w == w) && (xid->h == h))
530 return;
531 xid->x = x;
532 xid->y = y;
533 xid->w = w;
534 xid->h = h;
535 XMoveResizeWindow(disp, win, x, y, w, h);
536 }
537}
538
539int
540e_x_get_fd(void)
541{
542 return ConnectionNumber(disp);
543}
544
545void
546e_display_init(char *display)
547{
548 int revert;
549
550 xid_context = XUniqueContext();
551 disp = XOpenDisplay(display);
552 if (!disp)
553 {
554 char *d;
555
556 d = getenv("DISPLAY");
557 if (d)
558 fprintf(stderr,
559 "Fatal Error:\n"
560 "Cannot connect to the display nominated by your DISPLAY variable:\n"
561 "%s\n"
562 "Try changing your DISPLAY variable like:\n"
563 "DISPLAY=host:0 efm\n", d);
564 else
565 fprintf(stderr,
566 "Fatal Error:\n"
567 "No DISPLAY variable set so cannot determine display to connect to.\n"
568 "Try setting your DISPLAY variable like:\n"
569 "DISPLAY=host:0 efm\n");
570 exit(1);
571 }
572 XSetErrorHandler((XErrorHandler) e_handle_x_error);
573 XSetIOErrorHandler((XIOErrorHandler) e_handle_x_io_error);
574 default_vis = DefaultVisual(disp, DefaultScreen(disp));
575 default_depth = DefaultDepth(disp, DefaultScreen(disp));
576 default_cm = DefaultColormap(disp, DefaultScreen(disp));
577 default_win = DefaultRootWindow(disp);
578 default_root = DefaultRootWindow(disp);
579 mod_shift = e_mod_mask_shift_get();
580 mod_ctrl = e_mod_mask_ctrl_get();
581 mod_alt = e_mod_mask_alt_get();
582 mod_win = e_mod_mask_win_get();
583 XGetInputFocus(disp, &focused_win, &revert);
584 e_window_set_events(default_root, XEV_KEY | XEV_IN_OUT | XEV_MOUSE_MOVE |
585 XEV_CONFIGURE | XEV_CHILD_CHANGE | XEV_PROPERTY |
586 XEV_COLORMAP | XEV_VISIBILITY);
587 e_pointer_xy(0, NULL, NULL);
588 imlib_context_set_display(disp);
589 imlib_context_set_visual(default_vis);
590 imlib_context_set_colormap(default_cm);
591 imlib_context_set_drawable(default_root);
592 imlib_context_set_dither(0);
593 imlib_context_set_blend(1);
594}
595
596int
597e_events_pending(void)
598{
599 if (!disp) return 0;
600 return XPending(disp);
601}
602
603void
604e_get_next_event(XEvent * event)
605{
606 XNextEvent(disp, event);
607}
608
609int
610e_event_shape_get_id(void)
611{
612 int base = -1, err_base;
613
614 XShapeQueryExtension(disp, &base, &err_base);
615 base += ShapeNotify;
616 return base;
617}
618
619KeySym
620e_key_get_keysym_from_keycode(KeyCode keycode)
621{
622 return XKeycodeToKeysym(disp, keycode, 0);
623}
624
625char *
626e_key_get_string_from_keycode(KeyCode keycode)
627{
628 return e_string_dup(XKeysymToString(e_key_get_keysym_from_keycode(keycode)));
629}
630
631void
632e_event_allow(int mode, Time t)
633{
634 XAllowEvents(disp, mode, t);
635}
636
637int
638e_lock_mask_scroll_get(void)
639{
640 static int have_mask = 0;
641 static int mask = 0;
642 XModifierKeymap *mod;
643 KeyCode nl;
644 int i;
645 int masks[8] = {
646 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
647 Mod4Mask, Mod5Mask
648 };
649
650 if (have_mask)
651 return mask;
652 mod = XGetModifierMapping(disp);
653 nl = XKeysymToKeycode(disp, XK_Scroll_Lock);
654 if ((mod) && (mod->max_keypermod > 0))
655 {
656 for (i = 0; i < (8 * mod->max_keypermod); i++)
657 {
658 if ((nl) && (mod->modifiermap[i] == nl))
659 {
660 mask = masks[i / mod->max_keypermod];
661 if (mod->modifiermap)
662 XFree(mod->modifiermap);
663 XFree(mod);
664 have_mask = 1;
665 return mask;
666 }
667 }
668 }
669 if (mod)
670 {
671 if (mod->modifiermap)
672 XFree(mod->modifiermap);
673 XFree(mod);
674 }
675 return 0;
676}
677
678int
679e_lock_mask_num_get(void)
680{
681 static int have_mask = 0;
682 static int mask = 0;
683 XModifierKeymap *mod;
684 KeyCode nl;
685 int i;
686 int masks[8] = {
687 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
688 Mod4Mask, Mod5Mask
689 };
690
691 if (have_mask)
692 return mask;
693 mod = XGetModifierMapping(disp);
694 nl = XKeysymToKeycode(disp, XK_Num_Lock);
695 if ((mod) && (mod->max_keypermod > 0))
696 {
697 for (i = 0; i < (8 * mod->max_keypermod); i++)
698 {
699 if ((nl) && (mod->modifiermap[i] == nl))
700 {
701 mask = masks[i / mod->max_keypermod];
702 if (mod->modifiermap)
703 XFree(mod->modifiermap);
704 XFree(mod);
705 have_mask = 1;
706 return mask;
707 }
708 }
709 }
710 if (mod)
711 {
712 if (mod->modifiermap)
713 XFree(mod->modifiermap);
714 XFree(mod);
715 }
716 return 0;
717}
718
719int
720e_lock_mask_caps_get(void)
721{
722 static int have_mask = 0;
723 static int mask = 0;
724 XModifierKeymap *mod;
725 KeyCode nl;
726 int i;
727 int masks[8] = {
728 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
729 Mod4Mask, Mod5Mask
730 };
731
732 if (have_mask)
733 return mask;
734 mod = XGetModifierMapping(disp);
735 nl = XKeysymToKeycode(disp, XK_Caps_Lock);
736 if ((mod) && (mod->max_keypermod > 0))
737 {
738 for (i = 0; i < (8 * mod->max_keypermod); i++)
739 {
740 if ((nl) && (mod->modifiermap[i] == nl))
741 {
742 mask = masks[i / mod->max_keypermod];
743 if (mod->modifiermap)
744 XFree(mod->modifiermap);
745 XFree(mod);
746 have_mask = 1;
747 return mask;
748 }
749 }
750 }
751 if (mod)
752 {
753 if (mod->modifiermap)
754 XFree(mod->modifiermap);
755 XFree(mod);
756 }
757 return 0;
758}
759
760int
761e_mod_mask_shift_get(void)
762{
763 static int have_mask = 0;
764 static int mask = 0;
765 XModifierKeymap *mod;
766 KeyCode nl;
767 int i;
768 int masks[8] = {
769 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
770 Mod4Mask, Mod5Mask
771 };
772
773 if (have_mask)
774 return mask;
775 mod = XGetModifierMapping(disp);
776 nl = XKeysymToKeycode(disp, XK_Shift_L);
777 if ((mod) && (mod->max_keypermod > 0))
778 {
779 for (i = 0; i < (8 * mod->max_keypermod); i++)
780 {
781 if ((nl) && (mod->modifiermap[i] == nl))
782 {
783 mask = masks[i / mod->max_keypermod];
784 if (mod->modifiermap)
785 XFree(mod->modifiermap);
786 XFree(mod);
787 have_mask = 1;
788 return mask;
789 }
790 }
791 }
792 if (mod)
793 {
794 if (mod->modifiermap)
795 XFree(mod->modifiermap);
796 XFree(mod);
797 }
798 return 0;
799}
800
801int
802e_mod_mask_ctrl_get(void)
803{
804 static int have_mask = 0;
805 static int mask = 0;
806 XModifierKeymap *mod;
807 KeyCode nl;
808 int i;
809 int masks[8] = {
810 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
811 Mod4Mask, Mod5Mask
812 };
813
814 if (have_mask)
815 return mask;
816 mod = XGetModifierMapping(disp);
817 nl = XKeysymToKeycode(disp, XK_Control_L);
818 if ((mod) && (mod->max_keypermod > 0))
819 {
820 for (i = 0; i < (8 * mod->max_keypermod); i++)
821 {
822 if ((nl) && (mod->modifiermap[i] == nl))
823 {
824 mask = masks[i / mod->max_keypermod];
825 if (mod->modifiermap)
826 XFree(mod->modifiermap);
827 XFree(mod);
828 have_mask = 1;
829 return mask;
830 }
831 }
832 }
833 if (mod)
834 {
835 if (mod->modifiermap)
836 XFree(mod->modifiermap);
837 XFree(mod);
838 }
839 return 0;
840}
841
842int
843e_mod_mask_alt_get(void)
844{
845 static int have_mask = 0;
846 static int mask = 0;
847 XModifierKeymap *mod;
848 KeyCode nl;
849 int i;
850 int masks[8] = {
851 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
852 Mod4Mask, Mod5Mask
853 };
854
855 if (have_mask)
856 return mask;
857 mod = XGetModifierMapping(disp);
858 nl = XKeysymToKeycode(disp, XK_Alt_L);
859 if ((mod) && (mod->max_keypermod > 0))
860 {
861 for (i = 0; i < (8 * mod->max_keypermod); i++)
862 {
863 if ((nl) && (mod->modifiermap[i] == nl))
864 {
865 mask = masks[i / mod->max_keypermod];
866 if (mod->modifiermap)
867 XFree(mod->modifiermap);
868 XFree(mod);
869 have_mask = 1;
870 return mask;
871 }
872 }
873 }
874 if (mod)
875 {
876 if (mod->modifiermap)
877 XFree(mod->modifiermap);
878 XFree(mod);
879 }
880 return 0;
881}
882
883int
884e_mod_mask_win_get(void)
885{
886 static int have_mask = 0;
887 static int mask = 0;
888 XModifierKeymap *mod;
889 KeyCode nl;
890 int i;
891 int masks[8] = {
892 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
893 Mod4Mask, Mod5Mask
894 };
895
896 if (have_mask)
897 return mask;
898 mod = XGetModifierMapping(disp);