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 @@ +*.lo +*.la +.deps +.libs +Makefile +Makefile.in +aclocal.m4 +confdefs.h +config.cache +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +install-sh +libtool +ltconfig +ltmain.sh +missing +mkinstalldirs +stamp-h +stamp-h.in +*.tar.gz +macros +*~ +*.spec +.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 @@ +The Rasterman +Tom Gilbert 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 @@ +Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies of the Software, its documentation and marketing & publicity +materials, and acknowledgment shall be given in the documentation, materials +and software packages that this Software was used. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION 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 diff --git a/legacy/ecore/INSTALL b/legacy/ecore/INSTALL new file mode 100644 index 0000000000..e69de29bb2 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 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = src + +MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \ + config.h.in config.sub configure install-sh \ + ltconfig ltmain.sh missing mkinstalldirs \ + stamp-h.in + +install-data-local: + @$(NORMAL_INSTALL) + if test -d $(srcdir)/data; then \ + $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \ + for file in $(srcdir)/data/*; do \ + if test -f $$file; then \ + $(INSTALL_DATA) $$file $(DESTDIR)$(pkgdatadir)/; \ + fi \ + done \ + fi + +dist-hook: + if test -d data; then \ + mkdir $(distdir)/data; \ + for file in data/*; do \ + if test -f $$file; then \ + cp -p $$file $(distdir)/data; \ + fi \ + done \ + fi + +EXTRA_DIST = README AUTHORS COPYING diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/legacy/ecore/README b/legacy/ecore/README new file mode 100644 index 0000000000..e69de29bb2 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 @@ +#undef PACKAGE_LOCALE_DIR +#undef PACKAGE_DATA_DIR +#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 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +PKG_NAME="libecore" + +DIE=0 + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`autoconf' installed to." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +(grep "^AM_PROG_LIBTOOL" $srcdir/configure.in >/dev/null) && { + (libtool --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`libtool' installed." + echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 + } +} + +grep "^AM_GNU_GETTEXT" $srcdir/configure.in >/dev/null && { + grep "sed.*POTFILES" $srcdir/configure.in >/dev/null || \ + (gettext --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`gettext' installed." + echo "Get ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 + } +} + +grep "^AM_GNOME_GETTEXT" $srcdir/configure.in >/dev/null && { + grep "sed.*POTFILES" $srcdir/configure.in >/dev/null || \ + (gettext --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`gettext' installed." + echo "Get ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 + } +} + +(automake --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`automake' installed." + echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 + NO_AUTOMAKE=yes +} + + +# if no automake, don't bother testing for aclocal +test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: Missing \`aclocal'. The version of \`automake'" + echo "installed doesn't appear recent enough." + echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "**Warning**: I am going to run \`configure' with no arguments." + echo "If you wish to pass any to it, please specify them on the" + echo \`$0\'" command line." + echo +fi + +case $CC in +xlc ) + am_opt=--include-deps;; +esac + +for coin in `find $srcdir -name configure.in -print` +do + dr=`dirname $coin` + if test -f $dr/NO-AUTO-GEN; then + echo skipping $dr -- flagged as no auto-gen + else + echo processing $dr + macrodirs=`sed -n -e 's,AM_ACLOCAL_INCLUDE(\(.*\)),\1,gp' < $coin` + ( cd $dr + aclocalinclude="$ACLOCAL_FLAGS" + for k in $macrodirs; do + if test -d $k; then + aclocalinclude="$aclocalinclude -I $k" + ##else + ## echo "**Warning**: No such directory \`$k'. Ignored." + fi + done + if grep "^AM_GNU_GETTEXT" configure.in >/dev/null; then + if grep "sed.*POTFILES" configure.in >/dev/null; then + : do nothing -- we still have an old unmodified configure.in + else + echo "Creating $dr/aclocal.m4 ..." + test -r $dr/aclocal.m4 || touch $dr/aclocal.m4 + echo "Running gettextize... Ignore non-fatal messages." + echo "no" | gettextize --force --copy + echo "Making $dr/aclocal.m4 writable ..." + test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4 + fi + fi + if grep "^AM_GNOME_GETTEXT" configure.in >/dev/null; then + echo "Creating $dr/aclocal.m4 ..." + test -r $dr/aclocal.m4 || touch $dr/aclocal.m4 + echo "Running gettextize... Ignore non-fatal messages." + echo "no" | gettextize --force --copy + echo "Making $dr/aclocal.m4 writable ..." + test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4 + fi + if grep "^AM_PROG_LIBTOOL" configure.in >/dev/null; then + echo "Running libtoolize..." + libtoolize --force --copy + fi + echo "Running aclocal $aclocalinclude ..." + aclocal $aclocalinclude + if grep "^AM_CONFIG_HEADER" configure.in >/dev/null; then + echo "Running autoheader..." + autoheader + fi + echo "Running automake --gnu $am_opt ..." + automake --add-missing --gnu $am_opt + echo "Running autoconf ..." + autoconf + ) + fi +done + +#conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c + +if test x$NOCONFIGURE = x; then + echo Running $srcdir/configure $conf_flags "$@" ... + $srcdir/configure $conf_flags "$@" \ + && echo Now type \`make\' to compile $PKG_NAME +else + echo Skipping configure process. +fi 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 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(configure.in) +AM_INIT_AUTOMAKE(libecore, 0.1) +AM_CONFIG_HEADER(config.h) + +AC_ISC_POSIX +AC_PROG_CC +AM_PROG_CC_STDC +AC_HEADER_STDC +AM_PROG_LIBTOOL + +AM_WITH_DMALLOC + +dnl Set PACKAGE_LOCALE_DIR in config.h. +if test "x${prefix}" = "xNONE"; then + AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${ac_default_prefix}/${DATADIRNAME}/locale") +else + AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale") +fi + +dnl Set PACKAGE_DATA_DIR in config.h. +if test "x${datadir}" = 'x${prefix}/share'; then + if test "x${prefix}" = "xNONE"; then + AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${ac_default_prefix}/share/${PACKAGE}") + else + AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${prefix}/share/${PACKAGE}") + fi +else + AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${datadir}/${PACKAGE}") +fi + +dnl Set PACKAGE_SOURCE_DIR in config.h. +packagesrcdir=`cd $srcdir && pwd` +AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}") + +dnl Use -Wall if we have gcc. +changequote(,)dnl +if test "x$GCC" = "xyes"; then + case " $CFLAGS " in + *[\ \ ]-Wall[\ \ ]*) ;; + *) CFLAGS="$CFLAGS -Wall" ;; + esac +fi +changequote([,])dnl + +evas_cflags=`evas-config --cflags` +evas_libs=`evas-config --libs` +edb_cflags=`edb-config --cflags` +edb_libs=`edb-config --libs` + +AC_SUBST(evas_cflags) +AC_SUBST(evas_libs) +AC_SUBST(edb_cflags) +AC_SUBST(edb_libs) + +AC_OUTPUT([ +Makefile +src/Makefile +]) + 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 @@ +*.lo +*.la +.deps +.libs +Makefile +Makefile.in +aclocal.m4 +confdefs.h +config.cache +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +install-sh +libtool +ltconfig +ltmain.sh +missing +mkinstalldirs +stamp-h +stamp-h.in +*.tar.gz +macros +*~ +*.spec +.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 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES = \ + @evas_cflags@ @edb_cflags@ + +lib_LTLIBRARIES = libecore.la + +libecore_la_SOURCES = \ + e_ev_filter.c e_ev_filter.h \ + e_ev_signal.c e_ev_signal.h \ + e_ev_x.c e_ev_x.h \ + e_events.c e_events.h \ + e_mem.c e_mem.h \ + e_str.c e_str.h \ + e_util.c e_util.h \ + e_x.c e_x.h + +libecore_la_LIBADD = @evas_libs@ @edb_libs@ -lm + 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 @@ +#include "e_ev_filter.h" +#include "e_str.h" +#include "e_mem.h" +#include "e_util.h" + +typedef struct _ev_handler Ev_Handler; +typedef struct _ev_idle_handler Ev_Idle_Handler; + +struct _ev_handler +{ + void (*func) (Eevent * ev); + Ev_Handler *next; +}; + +struct _ev_idle_handler +{ + void (*func) (void *data); + void *data; + Ev_Idle_Handler *next; +}; + +static Ev_Handler *handler[EV_MAX]; +static Ev_Idle_Handler *idle_handlers = NULL; + +void +e_event_filter(Eevent * ev) +{ + Eevent *evp; + int motion_events = 0; + int dnd_pos_events = 0; + int dnd_status_events = 0; + + /* count events to only use last events of some types */ + for (evp = ev; evp; evp = evp->next) + { + if (evp->type == EV_MOUSE_MOVE) + motion_events++; + if (evp->type == EV_DND_DROP_POSITION) + dnd_pos_events++; + if (evp->type == EV_DND_DROP_STATUS) + dnd_status_events++; + } + for (evp = ev; evp; evp = evp->next) + { + if (evp->type == EV_MOUSE_MOVE) + { + if (motion_events > 1) + { + evp->ignore = 1; + motion_events--; + } + } + else if (evp->type == EV_DND_DROP_POSITION) + { + if (dnd_pos_events > 1) + { + evp->ignore = 1; + dnd_pos_events--; + } + } + else if (evp->type == EV_DND_DROP_STATUS) + { + if (dnd_status_events > 1) + { + evp->ignore = 1; + dnd_status_events--; + } + } + } +} + +void +e_event_filter_events_handle(Eevent * ev) +{ + Eevent *evp; + + for (evp = ev; evp; evp = evp->next) + { + Ev_Handler *h; + + for (h = handler[evp->type]; h; h = h->next) + { + if ((!evp->ignore) && (h->func)) + h->func(evp); + } + } +} + +void +e_event_filter_idle_handle(void) +{ + Ev_Idle_Handler *h; + + for (h = idle_handlers; h; h = h->next) + h->func(h->data); +} + +void +e_event_filter_init(void) +{ + int i; + + for (i = 0; i < EV_MAX; i++) + handler[i] = NULL; +} + +void +e_event_filter_handler_add(Eevent_Type type, void (*func) (Eevent * ev)) +{ + Ev_Handler *h; + + h = NEW(Ev_Handler, 1); + h->func = func; + h->next = handler[type]; + handler[type] = h; +} + +void +e_event_filter_idle_handler_add(void (*func) (void *data), void *data) +{ + Ev_Idle_Handler *h; + + h = NEW(Ev_Idle_Handler, 1); + h->func = func; + h->data = data; + h->next = idle_handlers; + idle_handlers = h; +} 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 @@ +#ifndef E_EV_FILTER_H +#define E_EV_FILTER_H 1 + +#include "e_events.h" + +void e_event_filter(Eevent * ev); +void e_event_filter_events_handle(Eevent * ev); +void e_event_filter_idle_handle(void); +void e_event_filter_init(void); +void e_event_filter_handler_add(Eevent_Type type, + void (*func) (Eevent * ev)); +void e_event_filter_idle_handler_add(void (*func) (void *data), + + void *data); +#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 @@ +#include "e_events.h" +#include "e_ev_signal.h" +#include "e_str.h" +#include "e_mem.h" +#include "e_util.h" +#include +#include +#include +#include + +static void e_ev_signal_free(void *event); +static void e_ev_signal_handle_sigchld(int num); +static void e_ev_signal_handle_sigusr1(int num); +static void e_ev_signal_handle_sigusr2(int num); +static void e_ev_signal_handle_sighup(int num); +static void e_ev_signal_handle_sigpipe(int num); +static void e_ev_signal_handle_sigsegv(int num); +static void e_ev_signal_handle_sigfpe(int num); +static void e_ev_signal_handle_sigill(int num); +static void e_ev_signal_handle_sigbus(int num); + +#ifdef HAVE_SIGSTKFLT +static void e_ev_signal_handle_sigstkflt(int num); +#endif +#ifdef HAVE_SIGPWR +static void e_ev_signal_handle_sigpwr(int num); +#endif +static void e_ev_signal_handle_sigchld(int num); +static void e_ev_signal_handle_all(pid_t pid); + +static int signal_chld_count = 0; +static int signal_usr1_count = 0; +static int signal_usr2_count = 0; +static int signal_hup_count = 0; + +/* freeing stuff */ +static void +e_ev_signal_free(void *event) +{ + FREE(event); +} + +/* signal handlers we can return from and add to signal recieved counts */ +static void +e_ev_signal_handle_sigchld(int num) +{ + signal_chld_count++; + return; + num = 0; +} + +static void +e_ev_signal_handle_sigusr1(int num) +{ + signal_usr1_count++; + return; + num = 0; +} + +static void +e_ev_signal_handle_sigusr2(int num) +{ + signal_usr2_count++; + return; + num = 0; +} + +static void +e_ev_signal_handle_sighup(int num) +{ + signal_hup_count++; + return; + num = 0; +} + +/* signals to ignore */ +static void +e_ev_signal_handle_sigpipe(int num) +{ + return; + num = 0; +} + +/* signal handlers we cant return from - so handle here */ +static void +e_ev_signal_handle_sigsegv(int num) +{ + for (;;) + { + fprintf(stderr, "EEEEEEEEK SEGV - waiting 10 seconds\n"); + sleep(10); + } + /* EEK - can't return - bad */ + abort(); + num = 0; +} + +static void +e_ev_signal_handle_sigfpe(int num) +{ + /* EEK - can't return - bad */ + abort(); + num = 0; +} + +static void +e_ev_signal_handle_sigill(int num) +{ + /* EEK - can't return - bad */ + abort(); + num = 0; +} + +static void +e_ev_signal_handle_sigbus(int num) +{ + /* EEK - can't return - bad */ + abort(); + num = 0; +} + +#ifdef HAVE_SIGSTKFLT +static void +e_ev_signal_handle_sigstkflt(int num) +{ + /* EEK - can't return - bad */ + abort(); + return; + num = 0; +} +#endif + +static void +e_ev_signal_handle_sigint(int num) +{ + exit(0); + return; + num = 0; +} + +static void +e_ev_signal_handle_sigquit(int num) +{ + exit(0); + return; + num = 0; +} + +static void +e_ev_signal_handle_sigabrt(int num) +{ + abort(); + return; + num = 0; +} + +static void +e_ev_signal_handle_sigalrm(int num) +{ + return; + num = 0; +} + +static void +e_ev_signal_handle_sigterm(int num) +{ + exit(0); + return; + num = 0; +} + +#ifdef HAVE_SIGPWR +static void +e_ev_signal_handle_sigpwr(int num) +{ + exit(0); + return; + num = 0; +} +#endif + +static void +e_ev_signal_handle_all(pid_t pid_pass) +{ + int status; + pid_t pid; + + if (signal_chld_count > 0) + { + while ((pid = waitpid(-1, &status, WNOHANG)) > 0) + { + if (WIFEXITED(status)) + { + Ev_Child *e; + int code; + + code = WEXITSTATUS(status); + e = NEW(Ev_Child, 1); + e->pid = pid; + e->exit_code = code; + e_add_event(EV_CHILD, e, e_ev_signal_free); + } + } + signal_chld_count = 0; + } + while (signal_usr1_count > 0) + { + Ev_User *e; + + e = NEW(Ev_User, 1); + e->num = 0; + e->hup = 0; + e_add_event(EV_USER, e, e_ev_signal_free); + signal_usr1_count--; + } + while (signal_hup_count > 0) + { + Ev_User *e; + + e = NEW(Ev_User, 1); + e->num = 0; + e->hup = 1; + e_add_event(EV_USER, e, e_ev_signal_free); + signal_hup_count--; + } + return; + pid_pass = 0; +} + +int +e_ev_signal_events_pending(void) +{ + return (signal_chld_count + signal_usr1_count + signal_hup_count); +} + +void +e_ev_signal_init(void) +{ + struct sigaction sa; + + e_add_event_pid(0, e_ev_signal_handle_all); + + sa.sa_handler = e_ev_signal_handle_sigchld; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGCHLD, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigusr1; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR1, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigusr2; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR2, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sighup; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGHUP, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigpipe; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGPIPE, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigsegv; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGSEGV, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigfpe; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGFPE, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigill; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGILL, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigbus; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGBUS, &sa, (struct sigaction *)0); +#ifdef HAVE_SIGSTKFLT + sa.sa_handler = e_ev_signal_handle_sigstkflt; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGSTKFLT, &sa, (struct sigaction *)0); +#endif + sa.sa_handler = e_ev_signal_handle_sigint; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigquit; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGQUIT, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigabrt; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGABRT, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigalrm; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGALRM, &sa, (struct sigaction *)0); + + sa.sa_handler = e_ev_signal_handle_sigterm; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGTERM, &sa, (struct sigaction *)0); +#ifdef HAVE_SIGPWR + sa.sa_handler = e_ev_signal_handle_sigpwr; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGPWR, &sa, (struct sigaction *)0); +#endif +} 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 @@ +#ifndef E_EV_SIGNAL_H +#define E_EV_SIGNAL_H 1 +void e_ev_signal_init(void); +int e_ev_signal_events_pending(void); +#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 @@ +#include "e_events.h" +#include "e_ev_x.h" +#include "e_str.h" +#include "e_mem.h" +#include "e_util.h" + +/* private funtion prototypes */ +static void e_ev_x_handle_events(int fd); +static void e_ev_x_translate_events(XEvent * events, int num_events); + +static void e_ev_key_down_free(void *event); +static void e_ev_key_up_free(void *event); +static void e_ev_generic_free(void *event); +static void e_ev_dnd_drop_request_free(void *event); + +static void e_ev_x_handle_key_press(XEvent * xevent); +static void e_ev_x_handle_key_release(XEvent * xevent); +static void e_ev_x_handle_button_press(XEvent * xevent); +static void e_ev_x_handle_button_release(XEvent * xevent); +static void e_ev_x_handle_motion_notify(XEvent * xevent); +static void e_ev_x_handle_enter_notify(XEvent * xevent); +static void e_ev_x_handle_leave_notify(XEvent * xevent); +static void e_ev_x_handle_focus_in(XEvent * xevent); +static void e_ev_x_handle_focus_out(XEvent * xevent); +static void e_ev_x_handle_expose(XEvent * xevent); +static void e_ev_x_handle_visibility_notify(XEvent * xevent); +static void e_ev_x_handle_create_notify(XEvent * xevent); +static void e_ev_x_handle_destroy_notify(XEvent * xevent); +static void e_ev_x_handle_unmap_notify(XEvent * xevent); +static void e_ev_x_handle_map_notify(XEvent * xevent); +static void e_ev_x_handle_map_request(XEvent * xevent); +static void e_ev_x_handle_reparent_notify(XEvent * xevent); +static void e_ev_x_handle_configure_notify(XEvent * xevent); +static void e_ev_x_handle_configure_request(XEvent * xevent); +static void e_ev_x_handle_circulate_notify(XEvent * xevent); +static void e_ev_x_handle_circulate_request(XEvent * xevent); +static void e_ev_x_handle_property_notify(XEvent * xevent); +static void e_ev_x_handle_colormap_notify(XEvent * xevent); +static void e_ev_x_handle_selection_notify(XEvent * xevent); +static void e_ev_x_handle_selection_request(XEvent * xevent); +static void e_ev_x_handle_client_message(XEvent * xevent); +static void e_ev_x_handle_shape_change(XEvent * xevent); + +static int max_event_id = 0; +static void (**event_translator) (XEvent * event) = NULL; + +static int lock_mask_scroll = 0, lock_mask_num = 0, lock_mask_caps = 0; +static int mod_mask_shift = 0, mod_mask_ctrl = 0, mod_mask_alt = + 0, mod_mask_win = 0; + +/* convenience macros */ +#define GETSET_MODS(state, mods) \ +(mods) = EV_KEY_MODIFIER_NONE;\ +if ((state) & mod_mask_shift) { e_mod_shift_set(1); (mods) |= EV_KEY_MODIFIER_SHIFT; }\ +else e_mod_shift_set(0);\ +if ((state) & mod_mask_ctrl) { e_mod_ctrl_set(1); (mods) |= EV_KEY_MODIFIER_CTRL; }\ +else e_mod_ctrl_set(0);\ +if ((state) & mod_mask_alt) { e_mod_alt_set(1); (mods) |= EV_KEY_MODIFIER_ALT; }\ +else e_mod_alt_set(0);\ +if ((state) & mod_mask_win) { e_mod_win_set(1); (mods) |= EV_KEY_MODIFIER_WIN; }\ +else e_mod_win_set(0); + +/* public functions */ + +/* initialise event handling for the fd X is on */ +void +e_ev_x_init(void) +{ + int i, shape_event_id, current_lock; + + shape_event_id = max_event_id = e_event_shape_get_id(); + event_translator = NEW_PTR(max_event_id + 1); + for (i = 0; i < max_event_id + 1; i++) + event_translator[i] = NULL; + event_translator[KeyPress] = e_ev_x_handle_key_press; + event_translator[KeyRelease] = e_ev_x_handle_key_release; + event_translator[ButtonPress] = e_ev_x_handle_button_press; + event_translator[ButtonRelease] = e_ev_x_handle_button_release; + event_translator[MotionNotify] = e_ev_x_handle_motion_notify; + event_translator[EnterNotify] = e_ev_x_handle_enter_notify; + event_translator[LeaveNotify] = e_ev_x_handle_leave_notify; + event_translator[FocusIn] = e_ev_x_handle_focus_in; + event_translator[FocusOut] = e_ev_x_handle_focus_out; + event_translator[Expose] = e_ev_x_handle_expose; + event_translator[VisibilityNotify] = e_ev_x_handle_visibility_notify; + event_translator[CreateNotify] = e_ev_x_handle_create_notify; + event_translator[DestroyNotify] = e_ev_x_handle_destroy_notify; + event_translator[UnmapNotify] = e_ev_x_handle_unmap_notify; + event_translator[MapNotify] = e_ev_x_handle_map_notify; + event_translator[MapRequest] = e_ev_x_handle_map_request; + event_translator[ReparentNotify] = e_ev_x_handle_reparent_notify; + event_translator[ConfigureNotify] = e_ev_x_handle_configure_notify; + event_translator[ConfigureRequest] = e_ev_x_handle_configure_request; + event_translator[CirculateNotify] = e_ev_x_handle_circulate_notify; + event_translator[CirculateRequest] = e_ev_x_handle_circulate_request; + event_translator[PropertyNotify] = e_ev_x_handle_property_notify; + event_translator[ColormapNotify] = e_ev_x_handle_colormap_notify; + event_translator[ClientMessage] = e_ev_x_handle_client_message; + event_translator[SelectionNotify] = e_ev_x_handle_selection_notify; + event_translator[SelectionRequest] = e_ev_x_handle_selection_request; + event_translator[shape_event_id] = e_ev_x_handle_shape_change; + + lock_mask_scroll = e_lock_mask_num_get(); + lock_mask_num = e_lock_mask_num_get(); + lock_mask_caps = e_lock_mask_scroll_get(); + + mod_mask_shift = e_mod_mask_shift_get(); + mod_mask_ctrl = e_mod_mask_ctrl_get(); + mod_mask_alt = e_mod_mask_alt_get(); + mod_mask_win = e_mod_mask_win_get(); + + e_key_grab("Num_Lock", EV_KEY_MODIFIER_NONE, 1, 1); + e_key_grab("Scroll_Lock", EV_KEY_MODIFIER_NONE, 1, 1); + e_key_grab("Caps_Lock", EV_KEY_MODIFIER_NONE, 1, 1); + current_lock = e_modifier_mask_get(); + if (current_lock & lock_mask_scroll) + e_lock_scroll_set(1); + if (current_lock & lock_mask_num) + e_lock_num_set(1); + if (current_lock & lock_mask_caps) + e_lock_caps_set(1); + if (current_lock & mod_mask_shift) + e_mod_shift_set(1); + if (current_lock & mod_mask_ctrl) + e_mod_ctrl_set(1); + if (current_lock & mod_mask_alt) + e_mod_alt_set(1); + if (current_lock & mod_mask_win) + e_mod_win_set(1); + e_add_event_fd(e_x_get_fd(), e_ev_x_handle_events); +} + +/* private functions */ +/* get all events onthe event queue and translate them */ +static void +e_ev_x_handle_events(int fd) +{ + int num_events = 0, size_events = 0; + XEvent *events = NULL; + + /* while there are events in the queue */ + while (e_events_pending()) + { + /* incriment our event count */ + num_events++; + /* if the numebr fo events is > than our buffer size then */ + if (num_events > size_events) + { + /* increase the buffer size by 64 events */ + size_events += 64; + if (events) + { + REALLOC(events, XEvent, size_events)} + else + events = NEW(XEvent, size_events); + } + /* get the next event into the event buffer */ + e_get_next_event(&(events[num_events - 1])); + } + /* call the XEvent -> Eevent translator */ + if (events) + { + e_ev_x_translate_events(events, num_events); + /* if theres an event buffer - free it */ + FREE(events); + } + return; + fd = 0; +} + +/* take an array of events and translate them into E events */ +static void +e_ev_x_translate_events(XEvent * events, int num_events) +{ + int i; + + for (i = 0; i < num_events; i++) + { + if ((events[i].type < max_event_id) && + (event_translator[events[i].type])) + (*(event_translator[events[i].type])) (&(events[i])); + } +} + +static void +e_ev_key_down_free(void *event) +{ + Ev_Key_Down *e; + + e = (Ev_Key_Down *) event; + IF_FREE(e->key); + IF_FREE(e->compose); + FREE(e); +} + +static void +e_ev_key_up_free(void *event) +{ + Ev_Key_Up *e; + + e = (Ev_Key_Up *) event; + IF_FREE(e->key); + IF_FREE(e->compose); + FREE(e); +} + +static void +e_ev_generic_free(void *event) +{ + FREE(event); +} + +static void +e_ev_dnd_drop_request_free(void *event) +{ + Ev_Dnd_Drop_Request *e; + + e = (Ev_Dnd_Drop_Request *) event; + if (e->files) + e_string_free_list(e->files, e->num_files); + FREE(event); +} + +static void +e_ev_x_handle_key_press(XEvent * xevent) +{ + Ev_Key_Down *e; + static KeyCode previous_code = 0; + static Time previous_time = 0; + + /* avoid doubling events up from passive grabs */ + if ((xevent->xkey.keycode == previous_code) && + xevent->xkey.time == previous_time) + return; + previous_code = xevent->xkey.keycode; + previous_time = xevent->xkey.time; + if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Scroll_Lock) + { + if (e_lock_scroll_get()) + e_lock_scroll_set(0); + else + e_lock_scroll_set(1); + e_event_allow(ReplayKeyboard, xevent->xkey.time); + e_flush(); + } + else if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Num_Lock) + { + if (e_lock_num_get()) + e_lock_num_set(0); + else + e_lock_num_set(1); + e_event_allow(ReplayKeyboard, xevent->xkey.time); + e_flush(); + } + else if (e_key_get_keysym_from_keycode(xevent->xkey.keycode) == XK_Caps_Lock) + { + if (e_lock_caps_get()) + e_lock_caps_set(0); + else + e_lock_caps_set(1); + e_event_allow(ReplayKeyboard, xevent->xkey.time); + e_flush(); + } + e = NEW(Ev_Key_Down, 1); + e->win = xevent->xkey.window; + e->root = xevent->xkey.root; + GETSET_MODS(xevent->xkey.state, e->mods); + e->time = xevent->xkey.time; + e->key = e_key_get_string_from_keycode(xevent->xkey.keycode); + { + int val; + char buf[256]; + KeySym sym; + XComposeStatus stat; + + val = XLookupString((XKeyEvent *) xevent, buf, sizeof(buf), &sym, &stat); + if (val > 0) + { + buf[val] = 0; + e->compose = e_string_dup(buf); + } + else + e->compose = NULL; + } + e_add_event(EV_KEY_DOWN, e, e_ev_key_down_free); +} + +static void +e_ev_x_handle_key_release(XEvent * xevent) +{ + Ev_Key_Up *e; + static KeyCode previous_code = 0; + static Time previous_time = 0; + + /* avoid doubling events up from passive grabs */ + if ((xevent->xkey.keycode == previous_code) && + xevent->xkey.time == previous_time) + return; + previous_code = xevent->xkey.keycode; + previous_time = xevent->xkey.time; + + e = NEW(Ev_Key_Up, 1); + e->win = xevent->xkey.window; + e->root = xevent->xkey.root; + GETSET_MODS(xevent->xkey.state, e->mods); + e->time = xevent->xkey.time; + e->key = e_key_get_string_from_keycode(xevent->xkey.keycode); + { + int val; + char buf[256]; + KeySym sym; + XComposeStatus stat; + + val = XLookupString((XKeyEvent *) xevent, buf, sizeof(buf), &sym, &stat); + if (val > 0) + { + buf[val] = 0; + e->compose = e_string_dup(buf); + } + else + e->compose = NULL; + } + e_add_event(EV_KEY_UP, e, e_ev_key_up_free); +} + +static void +e_ev_x_handle_button_press(XEvent * xevent) +{ + static Time last_time = 0, last_last_time = 0; + static int last_button = 0, last_last_button = 0; + static Window last_window = 0, last_last_window = 0; + + e_pointer_xy_set(xevent->xbutton.x_root, xevent->xbutton.y_root); + if ((xevent->xbutton.button == 4) || (xevent->xbutton.button == 5)) + { + Ev_Wheel *e; + + e = NEW(Ev_Wheel, 1); + e->win = xevent->xbutton.window; + e->root = xevent->xbutton.root; + e->x = xevent->xbutton.x; + e->y = xevent->xbutton.y; + e->rx = xevent->xbutton.x_root; + e->ry = xevent->xbutton.y_root; + e->time = xevent->xbutton.time; + if (xevent->xbutton.button == 5) + e->z = 1; + else + e->z = -1; + if (xevent->xbutton.time - last_time < 15) + e->z *= 16; + else if (xevent->xbutton.time - last_time < 30) + e->z *= 4; + GETSET_MODS(xevent->xbutton.state, e->mods); + e_add_event(EV_MOUSE_WHEEL, e, e_ev_generic_free); + } + else + { + Ev_Mouse_Down *e; + + e = NEW(Ev_Mouse_Down, 1); + e->win = xevent->xbutton.window; + e->root = xevent->xbutton.root; + e->button = xevent->xbutton.button; + e->x = xevent->xbutton.x; + e->y = xevent->xbutton.y; + e->rx = xevent->xbutton.x_root; + e->ry = xevent->xbutton.y_root; + e->time = xevent->xbutton.time; + e->double_click = 0; + e->triple_click = 0; + GETSET_MODS(xevent->xbutton.state, e->mods); + if (xevent->xbutton.time - last_last_time < 500) + { + if ((xevent->xbutton.window == (unsigned int)last_window) && + (last_window == last_last_window) && + (xevent->xbutton.button == (unsigned int)last_button) && + (last_button == last_button)) + e->triple_click = 1; + } + else if (xevent->xbutton.time - last_time < 250) + { + if ((xevent->xbutton.window == (unsigned int)last_window) && + (xevent->xbutton.button == (unsigned int)last_button)) + e->double_click = 1; + } + e_add_event(EV_MOUSE_DOWN, e, e_ev_generic_free); + } + last_last_window = last_window; + last_window = xevent->xbutton.window; + last_last_button = last_button; + last_button = xevent->xbutton.button; + last_last_time = last_time; + last_time = xevent->xbutton.time; +} + +static void +e_ev_x_handle_button_release(XEvent * xevent) +{ + Ev_Mouse_Up *e; + + if (xevent->xbutton.button > 3) + return; + + e = NEW(Ev_Mouse_Up, 1); + e->win = xevent->xbutton.window; + e->root = xevent->xbutton.root; + e->button = xevent->xbutton.button; + e->x = xevent->xbutton.x; + e->y = xevent->xbutton.y; + e->rx = xevent->xbutton.x_root; + e->ry = xevent->xbutton.y_root; + e->time = xevent->xbutton.time; + GETSET_MODS(xevent->xbutton.state, e->mods); + e_add_event(EV_MOUSE_UP, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_motion_notify(XEvent * xevent) +{ + Ev_Mouse_Move *e; + + e_pointer_xy_set(xevent->xmotion.x_root, xevent->xmotion.y_root); + e = NEW(Ev_Mouse_Move, 1); + e->win = xevent->xmotion.window; + e->root = xevent->xmotion.root; + e->x = xevent->xmotion.x; + e->y = xevent->xmotion.y; + e->rx = xevent->xmotion.x_root; + e->ry = xevent->xmotion.y_root; + e->time = xevent->xmotion.time; + GETSET_MODS(xevent->xmotion.state, e->mods); + e_add_event(EV_MOUSE_MOVE, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_enter_notify(XEvent * xevent) +{ + Ev_Window_Enter *e; + + e_pointer_xy_set(xevent->xcrossing.x_root, xevent->xcrossing.y_root); + e = NEW(Ev_Window_Enter, 1); + e->win = xevent->xcrossing.window; + e->root = xevent->xcrossing.root; + e->x = xevent->xcrossing.x; + e->y = xevent->xcrossing.y; + e->rx = xevent->xcrossing.x_root; + e->ry = xevent->xcrossing.y_root; + e->time = xevent->xcrossing.time; + GETSET_MODS(xevent->xcrossing.state, e->mods); + e_add_event(EV_MOUSE_IN, e, e_ev_generic_free); + e_window_mouse_set_in(e->win, 1); +} + +static void +e_ev_x_handle_leave_notify(XEvent * xevent) +{ + Ev_Window_Leave *e; + + e_pointer_xy_set(xevent->xcrossing.x_root, xevent->xcrossing.y_root); + e = NEW(Ev_Window_Leave, 1); + e->win = xevent->xcrossing.window; + e->root = xevent->xcrossing.root; + e->x = xevent->xcrossing.x; + e->y = xevent->xcrossing.y; + e->rx = xevent->xcrossing.x_root; + e->ry = xevent->xcrossing.y_root; + e->time = xevent->xcrossing.time; + GETSET_MODS(xevent->xcrossing.state, e->mods); + e_add_event(EV_MOUSE_OUT, e, e_ev_generic_free); + e_window_mouse_set_in(e->win, 0); +} + +static void +e_ev_x_handle_focus_in(XEvent * xevent) +{ + Ev_Window_Focus_In *e; + + e = NEW(Ev_Window_Focus_In, 1); + e->win = xevent->xfocus.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_FOCUS_IN, e, e_ev_generic_free); + e_focus_window_set(e->win); +} + +static void +e_ev_x_handle_focus_out(XEvent * xevent) +{ + Ev_Window_Focus_Out *e; + + e = NEW(Ev_Window_Focus_Out, 1); + e->win = xevent->xfocus.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_FOCUS_OUT, e, e_ev_generic_free); + e_focus_window_set(0); +} + +static void +e_ev_x_handle_expose(XEvent * xevent) +{ + Ev_Window_Expose *e; + + e = NEW(Ev_Window_Expose, 1); + e->win = xevent->xexpose.window; + e->root = e_window_get_root(e->win); + e->x = xevent->xexpose.x; + e->y = xevent->xexpose.y; + e->w = xevent->xexpose.width; + e->h = xevent->xexpose.height; + e_add_event(EV_WINDOW_EXPOSE, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_visibility_notify(XEvent * xevent) +{ + if (xevent->xvisibility.state != VisibilityPartiallyObscured) + { + Ev_Window_Visibility *e; + + e = NEW(Ev_Window_Visibility, 1); + e->win = xevent->xvisibility.window; + e->root = e_window_get_root(e->win); + if (xevent->xvisibility.state == VisibilityFullyObscured) + e->fully_obscured = 1; + else + e->fully_obscured = 0; + e_add_event(EV_WINDOW_VISIBILITY, e, e_ev_generic_free); + } +} + +static void +e_ev_x_handle_create_notify(XEvent * xevent) +{ + Ev_Window_Create *e; + + e = NEW(Ev_Window_Create, 1); + e->win = xevent->xcreatewindow.window; + e_validate_xid(e->win); + e->root = e_window_get_root(e->win); + if (xevent->xcreatewindow.override_redirect) + e->override = 1; + else + e->override = 0; + e_add_event(EV_WINDOW_CREATE, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_destroy_notify(XEvent * xevent) +{ + Ev_Window_Destroy *e; + + e = NEW(Ev_Window_Destroy, 1); + e->win = xevent->xdestroywindow.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_DESTROY, e, e_ev_generic_free); + e_unvalidate_xid(e->win); +} + +static void +e_ev_x_handle_unmap_notify(XEvent * xevent) +{ + Ev_Window_Unmap *e; + E_XID *xid = NULL; + + e = NEW(Ev_Window_Unmap, 1); + e->win = xevent->xunmap.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_UNMAP, e, e_ev_generic_free); + xid = e_validate_xid(e->win); + if (xid) + xid->mapped = 0; +} + +static void +e_ev_x_handle_map_notify(XEvent * xevent) +{ + Ev_Window_Map *e; + E_XID *xid = NULL; + + e = NEW(Ev_Window_Map, 1); + e->win = xevent->xmap.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_MAP, e, e_ev_generic_free); + xid = e_validate_xid(e->win); + if (xid) + xid->mapped = 1; +} + +static void +e_ev_x_handle_map_request(XEvent * xevent) +{ + Ev_Window_Map_Request *e; + + e = NEW(Ev_Window_Map_Request, 1); + e->win = xevent->xmaprequest.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_MAP_REQUEST, e, e_ev_generic_free); + e_validate_xid(e->win); +} + +static void +e_ev_x_handle_reparent_notify(XEvent * xevent) +{ + Ev_Window_Reparent *e; + Window parent; + E_XID *xid = NULL; + + e = NEW(Ev_Window_Reparent, 1); + e->win = xevent->xreparent.window; + xid = e_validate_xid(e->win); + e->root = e_window_get_root(e->win); + parent = e_window_get_parent(e->win); + e->parent_from = parent; + e->parent = xevent->xreparent.parent; + e_validate_xid(e->parent); + e_del_child(parent, e->win); + e_add_child(xevent->xreparent.parent, xevent->xreparent.window); + if (xid) + xid->parent = e->parent; + e_add_event(EV_WINDOW_REPARENT, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_configure_notify(XEvent * xevent) +{ + Ev_Window_Configure *e; + E_XID *xid; + + e = NEW(Ev_Window_Configure, 1); + e->win = xevent->xconfigure.window; + e->root = e_window_get_root(e->win); + e->x = xevent->xconfigure.x; + e->y = xevent->xconfigure.y; + e->w = xevent->xconfigure.width; + e->h = xevent->xconfigure.height; + if (!xevent->xconfigure.send_event) + { + xid = e_validate_xid(e->win); + if (xid) + { + xid->x = e->x; + xid->y = e->y; + xid->w = e->w; + xid->h = e->h; + } + e->wm_generated = 0; + /* FIXME: dont handle redioing stack for xevent->xconfigure.above */ + /* member (the window is stacked immediately in stack above this) */ + } + else + e->wm_generated = 1; + e_add_event(EV_WINDOW_CONFIGURE, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_configure_request(XEvent * xevent) +{ + Ev_Window_Configure_Request *e; + + e = NEW(Ev_Window_Configure_Request, 1); + e->win = xevent->xconfigurerequest.window; + e->root = e_window_get_root(e->win); + e->x = xevent->xconfigurerequest.x; + e->y = xevent->xconfigurerequest.y; + e->w = xevent->xconfigurerequest.width; + e->h = xevent->xconfigurerequest.height; + e->stack_win = xevent->xconfigurerequest.above; + e->detail = xevent->xconfigurerequest.detail; + e->mask = xevent->xconfigurerequest.value_mask; + e_add_event(EV_WINDOW_CONFIGURE_REQUEST, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_circulate_notify(XEvent * xevent) +{ + Ev_Window_Circulate *e; + + e = NEW(Ev_Window_Circulate, 1); + e->win = xevent->xcirculate.window; + e->root = e_window_get_root(e->win); + if (xevent->xcirculate.place == PlaceOnBottom) + e->lower = 1; + else + e->lower = 0; + e_add_event(EV_WINDOW_CIRCULATE, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_circulate_request(XEvent * xevent) +{ + Ev_Window_Circulate_Request *e; + + e = NEW(Ev_Window_Circulate_Request, 1); + e->win = xevent->xcirculaterequest.window; + e->root = e_window_get_root(e->win); + if (xevent->xcirculaterequest.place == PlaceOnBottom) + e->lower = 1; + else + e->lower = 0; + e_add_event(EV_WINDOW_CIRCULATE_REQUEST, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_property_notify(XEvent * xevent) +{ + Ev_Window_Property *e; + + e = NEW(Ev_Window_Property, 1); + e->win = xevent->xproperty.window; + e->root = e_window_get_root(e->win); + e->atom = xevent->xproperty.atom; + e->time = xevent->xproperty.time; + e_add_event(EV_WINDOW_PROPERTY, e, e_ev_generic_free); +} + +static void +e_ev_x_handle_colormap_notify(XEvent * xevent) +{ + Ev_Colormap *e; + + e = NEW(Ev_Colormap, 1); + e->win = xevent->xcolormap.window; + e->root = e_window_get_root(e->win); + e->cmap = xevent->xcolormap.colormap; + if (xevent->xcolormap.state == ColormapInstalled) + e->installed = 1; + else + e->installed = 0; + e_add_event(EV_COLORMAP, e, e_ev_generic_free); +} + +Ev_Dnd_Drop_Request *ev_drop_request_pending = NULL; + +static void +e_ev_x_handle_selection_notify(XEvent * xevent) +{ + Ev_Dnd_Drop_Request *e; + char *data; + int size; + static Atom atom_xdndactioncopy = 0; + static Atom atom_xdndactionmove = 0; + static Atom atom_xdndactionlink = 0; + static Atom atom_xdndactionask = 0; + static Atom atom_xdndactionlist = 0; + + e = ev_drop_request_pending; + if (!e) + return; + + E_ATOM(atom_xdndactioncopy, "XdndActionCopy"); + E_ATOM(atom_xdndactionmove, "XdndActionMove"); + E_ATOM(atom_xdndactionlink, "XdndActionLink"); + E_ATOM(atom_xdndactionask, "XdndActionAsk"); + E_ATOM(atom_xdndactionlist, "XdndActionList"); + data = e_dnd_selection_get(xevent->xany.window, e->source_win, + xevent->xselection.property, &size); + if (data) + { + char *s, *buf; + int i, is; + Atom *method = NULL; + + method = e_window_property_get(e->source_win, + atom_xdndactionlist, XA_ATOM, &is); + if (method) + { + e->copy = 0; + e->link = 0; + e->move = 0; + if (*method == atom_xdndactioncopy) + e->copy = 1; + else if (*method == atom_xdndactionmove) + e->move = 1; + else if (*method == atom_xdndactionlink) + e->link = 1; + FREE(method); + } + else + { + e->copy = 0; + e->link = 0; + e->move = 0; + } + s = data; + buf = NEW(char, size); + + i = 0; + is = 0; + e->files = NULL; + while ((s[is]) && (is < size)) + { + if ((i == 0) && (s[is] == '#')) + { + for (; ((s[is] != 0) && (s[is] != '\n')); is++); + } + else + { + if (s[is] != '\r') + { + buf[i++] = s[is]; + } + else + { + buf[i] = 0; + e->num_files++; + if (e->files) + { + REALLOC_PTR(e->files, e->num_files); + } + else + e->files = NEW_PTR(e->num_files); + e->files[e->num_files - 1] = e_string_dup(buf); + buf[0] = 0; + i = 0; + is++; + } + is++; + } + } + FREE(buf); + FREE(data); + } + e_add_event(EV_DND_DROP_REQUEST, e, e_ev_dnd_drop_request_free); + ev_drop_request_pending = NULL; +} + +static void +e_ev_x_handle_selection_request(XEvent * xevent) +{ + static Atom atom_xdndselection = 0; + static Atom atom_text_plain = 0; + Ev_Dnd_Data_Request *e; + + E_ATOM(atom_xdndselection, "XdndSelection"); + E_ATOM(atom_text_plain, "text/plain"); + if (xevent->xselectionrequest.selection == atom_xdndselection) + { + e = NEW(Ev_Dnd_Data_Request, 1); + e->win = xevent->xselectionrequest.owner; + e->root = e_window_get_root(e->win); + e->source_win = xevent->xselectionrequest.requestor; + if (xevent->xselectionrequest.target == atom_text_plain) + e->plain_text = 1; + else + e->plain_text = 0; + e->destination_atom = xevent->xselectionrequest.property; + e_add_event(EV_DND_DATA_REQUEST, e, e_ev_generic_free); + } +} + +static void +e_ev_x_handle_client_message(XEvent * xevent) +{ + static Atom atom_wm_delete_window = 0; + static Atom atom_wm_protocols = 0; + static Atom atom_xdndstatus = 0; + static Atom atom_xdndenter = 0; + static Atom atom_xdndleave = 0; + static Atom atom_xdndfinished = 0; + static Atom atom_xdndposition = 0; + static Atom atom_xdnddrop = 0; + static Atom atom_text_uri_list = 0; + static Atom atom_xdndactioncopy = 0; + static Atom atom_xdndactionlink = 0; + static Atom atom_xdndactionmove = 0; + + /* setup some known atoms to translate this message into a sensible event */ + E_ATOM(atom_wm_delete_window, "WM_DELETE_WINDOW"); + E_ATOM(atom_wm_protocols, "WM_PROTOCOLS"); + E_ATOM(atom_xdndstatus, "XdndStatus"); + E_ATOM(atom_xdndfinished, "XdndFinished"); + E_ATOM(atom_xdndenter, "XdndEnter"); + E_ATOM(atom_xdndleave, "XdndLeave"); + E_ATOM(atom_xdnddrop, "XdndDrop"); + E_ATOM(atom_xdndposition, "XdndPosition"); + E_ATOM(atom_xdndactioncopy, "XdndActionCopy"); + E_ATOM(atom_xdndactionlink, "XdndActionLink"); + E_ATOM(atom_xdndactionmove, "XdndActionMove"); + E_ATOM(atom_text_uri_list, "text/uri-list"); + /* forst type = delete event sent to client */ + if ((xevent->xclient.message_type == atom_wm_protocols) && + (xevent->xclient.format == 32) && + (xevent->xclient.data.l[0] == (long)atom_wm_delete_window)) + { + Ev_Window_Delete *e; + + e = NEW(Ev_Window_Delete, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e_add_event(EV_WINDOW_DELETE, e, e_ev_generic_free); + } + else if ((xevent->xclient.message_type == atom_xdndenter) && + (xevent->xclient.format == 32)) + { + if (xevent->xclient.data.l[2] == (long)atom_text_uri_list) + { + Ev_Dnd_Drop_Request *e; + + if (ev_drop_request_pending) + { + e_ev_dnd_drop_request_free(ev_drop_request_pending); + ev_drop_request_pending = NULL; + } + e = NEW(Ev_Dnd_Drop_Request, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + if (!e_dnd_selection_convert + (e->source_win, e->win, atom_text_uri_list)) + { + FREE(e); + return; + } + e->files = NULL; + e->num_files = 0; + ev_drop_request_pending = e; + } + } + else if ((xevent->xclient.message_type == atom_xdndleave) && + (xevent->xclient.format == 32)) + { + Ev_Dnd_Drop_End *e; + + e = NEW(Ev_Dnd_Drop_End, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + e_add_event(EV_DND_DROP_END, e, e_ev_generic_free); + } + else if ((xevent->xclient.message_type == atom_xdndposition) && + (xevent->xclient.format == 32)) + { + Ev_Dnd_Drop_Position *e; + + e = NEW(Ev_Dnd_Drop_Position, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + e->x = (xevent->xclient.data.l[2] >> 16) & 0xffff; + e->y = xevent->xclient.data.l[2] & 0xffff; + e_add_event(EV_DND_DROP_POSITION, e, e_ev_generic_free); + } + else if ((xevent->xclient.message_type == atom_xdndstatus) && + (xevent->xclient.format == 32)) + { + Ev_Dnd_Drop_Status *e; + + e = NEW(Ev_Dnd_Drop_Status, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + e->x = (xevent->xclient.data.l[2] >> 16) & 0xffff; + e->y = xevent->xclient.data.l[2] & 0xffff; + e->w = (xevent->xclient.data.l[3] >> 16) & 0xffff; + e->h = xevent->xclient.data.l[3] & 0xffff; + if (xevent->xclient.data.l[1] & 0x1) + e->ok = 1; + else + e->ok = 0; + e_add_event(EV_DND_DROP_STATUS, e, e_ev_generic_free); + } + else if ((xevent->xclient.message_type == atom_xdndfinished) && + (xevent->xclient.format == 32)) + { + Ev_Dnd_Drop_End *e; + + e = NEW(Ev_Dnd_Drop_End, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + e_add_event(EV_DND_DROP_END, e, e_ev_generic_free); + } + else if ((xevent->xclient.message_type == atom_xdnddrop) && + (xevent->xclient.format == 32)) + { + Ev_Dnd_Drop *e; + + e = NEW(Ev_Dnd_Drop, 1); + e->win = xevent->xclient.window; + e->root = e_window_get_root(e->win); + e->source_win = (Window) xevent->xclient.data.l[0]; + e_add_event(EV_DND_DROP, e, e_ev_generic_free); + } + else + { + Ev_Message *e; + + e = NEW(Ev_Message, 1); + e->win = xevent->xclient.window; + e->format = xevent->xclient.format; + e->atom = xevent->xclient.message_type; + MEMCPY(xevent->xclient.data.b, e->data.b, char, 20); + + e_add_event(EV_MESSAGE, e, e_ev_generic_free); + } +} + +static void +e_ev_x_handle_shape_change(XEvent * xevent) +{ + Ev_Window_Shape *e; + XShapeEvent *shape_event; + + shape_event = (XShapeEvent *) xevent; + e = NEW(Ev_Window_Shape, 1); + e->win = shape_event->window; + e->root = e_window_get_root(e->win); + e->time = shape_event->time; + e_add_event(EV_WINDOW_SHAPE, e, e_ev_generic_free); +} + +char * +e_key_press_translate_into_typeable(Ev_Key_Down * e) +{ + /* exceptions */ + if ((e_string_cmp(e->key, "Delete")) || + (e_string_cmp(e->key, "BackSpace")) || + (e_string_cmp(e->key, "Tab")) || + (e_string_cmp(e->key, "Escape")) || + (e_string_cmp(e->key, "Return")) || + (e_string_cmp(e->key, "KP_Enter")) || + (e_string_cmp(e->key, "Enter")) || + (e_string_cmp(e->key, "KP_Divide")) || + (e_string_cmp(e->key, "KP_Multiply")) || + (e_string_cmp(e->key, "KP_Subtract")) || + (e_string_cmp(e->key, "KP_Add")) || (e_string_cmp(e->key, "Enter"))) + return NULL; + return e->compose; +} 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 @@ +#ifndef E_EV_X_H +#define E_EV_X_H 1 +void e_ev_x_init(void); +char *e_key_press_translate_into_typeable(Ev_Key_Down * e); +#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 @@ +#include "e_events.h" +#include "e_ev_filter.h" +#include "e_str.h" +#include "e_mem.h" +#include "e_util.h" +#include "e_ev_signal.h" +#include +#include + +/* glocal (yes global/local) variabels for events */ +Ev_Fd_Handler *fd_handlers = NULL; +Ev_Ipc_Handler *ipc_handlers = NULL; +Ev_Pid_Handler *pid_handlers = NULL; +Ev_Timer *timers = NULL; + +Eevent *events = NULL; +Eevent *last_event = NULL; + +/* local functions for event handling */ +static void e_handle_event_timer(void); +static void e_handle_zero_event_timer(void); + +/* public functions */ + +/* add an event to the end of the event queue */ +void +e_add_event(Eevent_Type type, void *event, void (*ev_free) (void *event)) +{ + Eevent *ev; + + ev = NEW(Eevent, 1); + ev->type = type; + ev->ignore = 0; + ev->event = event; + ev->next = NULL; + ev->ev_free = ev_free; + if (!events) + events = ev; + else + last_event->next = ev; + last_event = ev; +} + +/* delete an event from the event queue */ +void +e_del_event(void *event) +{ + Eevent *ev, *pev; + + pev = NULL; + ev = events; + while (ev) + { + if (ev->event == event) + { + if (pev) + pev->next = ev->next; + else + events = ev->next; + if (!ev->next) + last_event = pev; + if ((ev->event) && (ev->ev_free)) + (*ev->ev_free) (ev->event); + FREE(ev); + return; + } + pev = ev; + ev = ev->next; + } +} + +void +e_del_all_events(void) +{ + Eevent *ev, *pev; + + ev = events; + while (ev) + { + pev = ev; + ev = ev->next; + if ((pev->event) && (pev->ev_free)) + pev->ev_free(pev->event); + FREE(pev); + } + events = NULL; + last_event = NULL; +} + +Eevent * +e_get_last_event(void) +{ + return last_event; +} + +/* add a callback handler if fd is active for reading */ +void +e_add_event_fd(int fd, void (*func) (int fd)) +{ + Ev_Fd_Handler *fd_h; + + /* new handler struct */ + fd_h = NEW(Ev_Fd_Handler, 1); + fd_h->next = fd_handlers; + fd_h->fd = fd; + fd_h->func = func; + fd_handlers = fd_h; +} + +/* delete handler for fd */ +void +e_del_event_fd(int fd) +{ + START_LIST_DEL(Ev_Fd_Handler, fd_handlers, (_p->fd == fd)); + FREE(_p); + END_LIST_DEL; +} + +void +e_add_event_pid(pid_t pid, void (*func) (pid_t pid)) +{ + Ev_Pid_Handler *pid_h; + + /* delete the old handler */ + e_del_event_pid(pid); + /* new handler struct */ + pid_h = NEW(Ev_Pid_Handler, 1); + pid_h->next = pid_handlers; + pid_h->pid = pid; + pid_h->func = func; + pid_handlers = pid_h; +} + +void +e_del_event_pid(pid_t pid) +{ + START_LIST_DEL(Ev_Pid_Handler, pid_handlers, (_p->pid == pid)); + FREE(_p); + END_LIST_DEL; +} + +void +e_add_event_ipc(int ipc, void (*func) (int ipc)) +{ + Ev_Ipc_Handler *ipc_h; + + /* delete the old handler */ + e_del_event_ipc(ipc); + /* new handler struct */ + ipc_h = NEW(Ev_Ipc_Handler, 1); + ipc_h->next = ipc_handlers; + ipc_h->ipc = ipc; + ipc_h->func = func; + ipc_handlers = ipc_h; +} + +void +e_del_event_ipc(int ipc) +{ + START_LIST_DEL(Ev_Ipc_Handler, ipc_handlers, (_p->ipc == ipc)); + FREE(_p); + END_LIST_DEL; +} + +/* sit in this loop forever and process events */ +void +e_event_loop(void) +{ + int count, fdsize, timed_out, were_events; + double time1, time2, prev_time = 0.0; + struct timeval tval; + fd_set fdset; + Ev_Fd_Handler *fd_h; + Ev_Pid_Handler *pid_h; + Ev_Ipc_Handler *ipc_h; + + /* init some of the time variables */ + time1 = e_get_time(); + time2 = time1 - prev_time; + prev_time = time1; + for (;;) + { + /* state setup */ + timed_out = 0; + were_events = 0; + + /* setup fd array from list of listening fd's */ + fdsize = 0; + FD_ZERO(&fdset); + /* for ever fd handler add the fd to the array and incriment fdsize */ + for (fd_h = fd_handlers; fd_h; fd_h = fd_h->next) + { + FD_SET(fd_h->fd, &fdset); + if (fd_h->fd > fdsize) + fdsize = fd_h->fd; + } + count = 1; + /* if there are timers setup adjust timeout value and select */ + if (timers) + { + if (timers->just_added) + { + timers->just_added = 0; + time1 = timers->in; + } + else + { + time1 = timers->in - time2; + if (time1 < 0.0) + time1 = 0.0; + timers->in = time1; + } + tval.tv_sec = (long)time1; + tval.tv_usec = (long)((time1 - ((double)tval.tv_sec)) * 1000000); + if (tval.tv_sec < 0) + tval.tv_sec = 0; + if (tval.tv_usec <= 1000) + tval.tv_usec = 1000; + e_handle_zero_event_timer(); + if ((!e_events_pending()) && + (!e_ev_signal_events_pending())) + count = select(fdsize + 1, &fdset, NULL, NULL, &tval); + } + /* no timers - just sit and block */ + else + { + if (e_db_runtime_flush()) + { + if ((!e_events_pending()) && + (!e_ev_signal_events_pending())) + count = select(fdsize + 1, &fdset, NULL, NULL, NULL); + } + else + { + tval.tv_sec = 1; + tval.tv_usec = 0; + if ((!e_events_pending()) && + (!e_ev_signal_events_pending())) + count = select(fdsize + 1, &fdset, NULL, NULL, &tval); + } + } + for (pid_h = pid_handlers; pid_h; pid_h = pid_h->next) + pid_h->func(pid_h->pid); + for (ipc_h = ipc_handlers; ipc_h; ipc_h = ipc_h->next) + ipc_h->func(ipc_h->ipc); + /* return < 0 - error or signal interrupt */ + if (count < 0) + { + /* error */ + if ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF)) + { + fprintf(stderr, "EEEEEEEEEEEEEEEEEEEEK\n"); + exit(1); + } + } + /* timers are available and its a timeout */ + if ((timers) && (count == 0)) + { + e_handle_event_timer(); + timed_out = 1; + } + if (count < 0) + count = 0; + if (e_events_pending()) + { + count++; + FD_SET(e_x_get_fd(), &fdset); + } + /* fd's are active */ + if (count > 0) + { + /* for every fd handler - if its fd si set - call the func */ + for (fd_h = fd_handlers; fd_h;) + { + Ev_Fd_Handler *fdh; + + fdh = fd_h; + fd_h = fd_h->next; + if (FD_ISSET(fdh->fd, &fdset)) + fdh->func(fdh->fd); + } + } + if (events) + e_event_filter(events); + if (events) + { + e_event_filter_events_handle(events); + were_events = 1; + } + e_del_all_events(); + if ((timed_out) || (were_events)) + e_event_filter_idle_handle(); + e_flush(); + time1 = e_get_time(); + time2 = time1 - prev_time; + prev_time = time1; + } +} + +/* add a timeout funcitont o be called in "in" seconds with name name */ +void +e_add_event_timer(char *name, double in, void (*func) (int val, void *data), + int val, void *data) +{ + Ev_Timer *timer, *ptr, *pptr; + double tally; + + if (name) + e_del_event_timer(name); + timer = NEW(Ev_Timer, 1); + timer->next = NULL; + timer->func = func; + timer->data = data; + timer->val = val; + timer->just_added = 1; + timer->in = in; + timer->name = e_string_dup(name); + if (!timers) + timers = timer; + else + { + pptr = NULL; + ptr = timers; + tally = 0.0; + while (ptr) + { + tally += ptr->in; + if (tally > in) + { + tally -= ptr->in; + timer->next = ptr; + if (pptr) + pptr->next = timer; + else + timers = timer; + timer->in -= tally; + if (timer->next) + timer->next->in -= timer->in; + return; + } + pptr = ptr; + ptr = ptr->next; + } + if (pptr) + pptr->next = timer; + else + timers = timer; + timer->in -= tally; + } +} + +/* delete a timer timeout entry named "name" */ +void * +e_del_event_timer(char *name) +{ + Ev_Timer *timer, *ptr, *pptr; + + pptr = NULL; + ptr = timers; + while (ptr) + { + timer = ptr; + if (e_string_cmp(timer->name, name)) + { + void *data; + + if (pptr) + pptr->next = timer->next; + else + timers = timer->next; + if (timer->next) + timer->next->in += timer->in; + IF_FREE(timer->name); + data = timer->data; + FREE(timer); + return data; + } + pptr = ptr; + ptr = ptr->next; + } + return NULL; +} + +/* private functions */ +static void +e_handle_event_timer(void) +{ + Ev_Timer *timer; + + if (!timers) + return; + timer = timers; + timers = timer->next; + (*(timer->func)) (timer->val, timer->data); + IF_FREE(timer->name); + FREE(timer); +} + +static void +e_handle_zero_event_timer(void) +{ + while ((timers) && (timers->in == 0.0)) + e_handle_event_timer(); +} 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 @@ +#ifndef E_EVENTS_H +#define E_EVENTS_H 1 + +#include +#include +#include +#include "e_x.h" + +typedef struct _eev Eevent; +typedef struct _ev_fd_handler Ev_Fd_Handler; +typedef struct _ev_pid_handler Ev_Pid_Handler; +typedef struct _ev_ipc_handler Ev_Ipc_Handler; +typedef struct _ev_timer Ev_Timer; + +typedef struct _ev_key_down Ev_Key_Down; +typedef struct _ev_key_up Ev_Key_Up; +typedef struct _ev_mouse_down Ev_Mouse_Down; +typedef struct _ev_mouse_up Ev_Mouse_Up; +typedef struct _ev_wheel Ev_Wheel; +typedef struct _ev_mouse_move Ev_Mouse_Move; +typedef struct _ev_window_enter Ev_Window_Enter; +typedef struct _ev_window_leave Ev_Window_Leave; +typedef struct _ev_window_focus_in Ev_Window_Focus_In; +typedef struct _ev_window_focus_out Ev_Window_Focus_Out; +typedef struct _ev_window_expose Ev_Window_Expose; +typedef struct _ev_window_visibility Ev_Window_Visibility; +typedef struct _ev_window_create Ev_Window_Create; +typedef struct _ev_window_destroy Ev_Window_Destroy; +typedef struct _ev_window_map Ev_Window_Map; +typedef struct _ev_window_unmap Ev_Window_Unmap; +typedef struct _ev_window_map_request Ev_Window_Map_Request; +typedef struct _ev_window_reparent Ev_Window_Reparent; +typedef struct _ev_window_configure Ev_Window_Configure; +typedef struct _ev_window_configure_request Ev_Window_Configure_Request; +typedef struct _ev_window_circulate Ev_Window_Circulate; +typedef struct _ev_window_circulate_request Ev_Window_Circulate_Request; +typedef struct _ev_window_property Ev_Window_Property; +typedef struct _ev_window_shape Ev_Window_Shape; +typedef struct _ev_client_message Ev_Message; +typedef struct _ev_colormap Ev_Colormap; +typedef struct _ev_window_delete Ev_Window_Delete; +typedef struct _ev_child Ev_Child; +typedef struct _ev_user Ev_User; +typedef struct _ev_file_progress Ev_File_Progress; +typedef struct _ev_file_update Ev_File_Update; +typedef struct _ev_dnd_drop_request Ev_Dnd_Drop_Request; +typedef struct _ev_dnd_drop_end Ev_Dnd_Drop_End; +typedef struct _ev_dnd_drop_position Ev_Dnd_Drop_Position; +typedef struct _ev_dnd_drop Ev_Dnd_Drop; +typedef struct _ev_dnd_drop_status Ev_Dnd_Drop_Status; +typedef struct _ev_dnd_data_request Ev_Dnd_Data_Request; + +enum _eev_stack_detail +{ + EV_STACK_ABOVE = Above, + EV_STACK_BELOW = Below, + EV_STACK_TOP_IF = TopIf, + EV_STACK_BOTTOM_IF = BottomIf, + EV_STACK_OPPOSITE = Opposite +}; + +enum _eev_value_mask +{ + EV_VALUE_X = CWX, + EV_VALUE_Y = CWY, + EV_VALUE_W = CWWidth, + EV_VALUE_H = CWHeight, + EV_VALUE_BORDER = CWBorderWidth, + EV_VALUE_SIBLING = CWSibling, + EV_VALUE_STACKING = CWStackMode +}; + +enum _eev_type +{ + EV_MOUSE_MOVE, + EV_MOUSE_DOWN, + EV_MOUSE_UP, + EV_MOUSE_IN, + EV_MOUSE_OUT, + EV_MOUSE_WHEEL, + EV_KEY_DOWN, + EV_KEY_UP, + EV_WINDOW_MAP, + EV_WINDOW_UNMAP, + EV_WINDOW_CREATE, + EV_WINDOW_DESTROY, + EV_WINDOW_CONFIGURE, + EV_WINDOW_CONFIGURE_REQUEST, + EV_WINDOW_MAP_REQUEST, + EV_WINDOW_PROPERTY, + EV_WINDOW_CIRCULATE, + EV_WINDOW_CIRCULATE_REQUEST, + EV_WINDOW_REPARENT, + EV_WINDOW_EXPOSE, + EV_WINDOW_VISIBILITY, + EV_WINDOW_SHAPE, + EV_WINDOW_FOCUS_IN, + EV_WINDOW_FOCUS_OUT, + EV_MESSAGE, + EV_WINDOW_DELETE, + EV_COLORMAP, + + EV_DND_DROP_REQUEST, + EV_DND_DROP_END, + EV_DND_DROP_POSITION, + EV_DND_DROP, + EV_DND_DROP_STATUS, + EV_DND_DATA_REQUEST, + + EV_CHILD, + EV_USER, + + EV_MAX +}; + +typedef enum _eev_type Eevent_Type; +typedef enum _eev_stack_detail Ev_Stack_Detail; +typedef enum _eev_value_mask Ev_Confgure_Value_Mask; + +struct _eev +{ + Eevent_Type type; + char ignore; + void *event; + void (*ev_free) (void *evnt); + Eevent *next; +}; + +struct _ev_fd_handler +{ + int fd; + void (*func) (int fd); + Ev_Fd_Handler *next; +}; + +struct _ev_pid_handler +{ + pid_t pid; + void (*func) (pid_t pid); + Ev_Pid_Handler *next; +}; + +struct _ev_ipc_handler +{ + int ipc; + void (*func) (int ipc); + Ev_Ipc_Handler *next; +}; + +struct _ev_timer +{ + char *name; + void (*func) (int val, void *data); + int val; + void *data; + double in; + char just_added; + Ev_Timer *next; +}; + +struct _ev_key_down +{ + Window win, root; + Ev_Key_Modifiers mods; + char *key; + char *compose; + Time time; +}; + +struct _ev_key_up +{ + Window win, root; + Ev_Key_Modifiers mods; + char *key; + char *compose; + Time time; +}; + +struct _ev_mouse_down +{ + Window win, root; + Ev_Key_Modifiers mods; + int button; + int x, y; + int rx, ry; + int double_click, triple_click; + Time time; +}; + +struct _ev_mouse_up +{ + Window win, root; + Ev_Key_Modifiers mods; + int button; + int x, y; + int rx, ry; + Time time; +}; + +struct _ev_wheel +{ + Window win, root; + Ev_Key_Modifiers mods; + int x, y, z; + int rx, ry; + Time time; +}; + +struct _ev_mouse_move +{ + Window win, root; + Ev_Key_Modifiers mods; + int x, y; + int rx, ry; + Time time; +}; + +struct _ev_window_enter +{ + Window win, root; + int x, y; + int rx, ry; + Ev_Key_Modifiers mods; + Time time; +}; + +struct _ev_window_leave +{ + Window win, root; + int x, y; + int rx, ry; + Ev_Key_Modifiers mods; + Time time; +}; + +struct _ev_window_focus_in +{ + Window win, root; + Time time; +}; + +struct _ev_window_focus_out +{ + Window win, root; + Time time; +}; + +struct _ev_window_expose +{ + Window win, root; + int x, y, w, h; +}; + +struct _ev_window_visibility +{ + Window win, root; + int fully_obscured; +}; + +struct _ev_window_create +{ + Window win, root; + int override; +}; + +struct _ev_window_destroy +{ + Window win, root; +}; + +struct _ev_window_map +{ + Window win, root; +}; + +struct _ev_window_unmap +{ + Window win, root; +}; + +struct _ev_window_map_request +{ + Window win, root; +}; + +struct _ev_window_reparent +{ + Window win, root; + Window parent_from, parent; +}; + +struct _ev_window_configure +{ + Window win, root; + int x, y, w, h; + int wm_generated; +}; + +struct _ev_window_configure_request +{ + Window win, root; + int x, y, w, h; + int border; + Window stack_win; + Ev_Stack_Detail detail; + Ev_Confgure_Value_Mask mask; +}; + +struct _ev_window_circulate +{ + Window win, root; + int lower; +}; + +struct _ev_window_circulate_request +{ + Window win, root; + int lower; +}; + +struct _ev_window_property +{ + Window win, root; + Atom atom; + Time time; +}; + +struct _ev_window_shape +{ + Window win, root; + Time time; +}; + +struct _ev_client_message +{ + Window win; + int format; + Atom atom; + union + { + char b[20]; + short s[10]; + long l[5]; + } + data; +}; + +struct _ev_colormap +{ + Window win, root; + Colormap cmap; + int installed; +}; + +struct _ev_window_delete +{ + Window win, root; +}; + +struct _ev_dnd_drop_request +{ + Window win, root, source_win; + int num_files; + char **files; + int copy, link, move; +}; + +struct _ev_dnd_drop_end +{ + Window win, root, source_win; +}; + +struct _ev_dnd_drop_position +{ + Window win, root, source_win; + int x, y; +}; + +struct _ev_dnd_drop +{ + Window win, root, source_win; +}; + +struct _ev_dnd_drop_status +{ + Window win, root, source_win; + int x, y, w, h; + int ok; +}; + +struct _ev_dnd_data_request +{ + Window win, root, source_win; + int plain_text; + Atom destination_atom; +}; + +struct _ev_child +{ + pid_t pid; + int exit_code; +}; + +struct _ev_user +{ + int num; + int hup; +}; + +void e_add_event(Eevent_Type type, void *event, + void (*ev_free) (void *event)); +void e_del_event(void *event); +void e_del_all_events(void); +Eevent *e_get_last_event(void); + +void e_add_event_fd(int fd, void (*func) (int fd)); +void e_del_event_fd(int fd); +void e_add_event_pid(pid_t pid, void (*func) (pid_t pid)); +void e_del_event_pid(pid_t pid); +void e_add_event_ipc(int ipc, void (*func) (int ipc)); +void e_del_event_ipc(int ipc); + +void e_event_loop(void); + +void e_add_event_timer(char *name, double in, + void (*func) (int val, void *data), + int val, void *data); +void *e_del_event_timer(char *name); + +#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 @@ +#ifndef E_MEM_H +#define E_MEM_H 1 + +#include +#include +#include + +#define MEMCPY(src, dst, type, num) memcpy(dst, src, sizeof(type) * (num)) + +#if 1 +#define NEW(dat, num) malloc(sizeof(dat) * (num)) +#define NEW_PTR(num) malloc(sizeof(void *) * (num)) +#define FREE(dat) {if (dat) {free(dat); dat = NULL;} else {printf("eek - NULL free\n");sleep(30);}} +#define IF_FREE(dat) {if (dat) FREE(dat);} +#define REALLOC(dat, type, num) {if (dat) dat = realloc(dat, sizeof(type) * (num)); else dat = malloc(sizeof(type) * (num));} +#define REALLOC_PTR(dat, num) {if (dat) dat = realloc(dat, sizeof(void *) * (num)); else dat = malloc(sizeof(void *) * (num));} + +#else +static void * +_NEW(int size, int num) +{ + void *dat; + + dat = malloc(size * num); + printf("NEW(%i) = %p\n", size * num, dat); + return dat; +} +static void * +_NEW_PTR(int num) +{ + void *dat; + + dat = malloc(sizeof(void *) * num); + printf("NEW(%i) = %p\n", sizeof(void *) * num, dat); + + return dat; +} +static void +_IF_FREE(void *dat) +{ + printf("IF_FREE(%p)\n", dat); + if (dat) + free(dat); +} +static void +_FREE(void *dat) +{ + printf("FREE(%p)\n", dat); + free(dat); +} +#define NEW(dat, num) _NEW(sizeof(dat), (num)) +#define NEW_PTR(num) _NEW(sizeof(void *), (num)) +#define IF_FREE(dat) {_IF_FREE(dat);} +#define FREE(dat) {_FREE(dat);} + +#define REALLOC(dat, type, num) {dat = realloc(dat, sizeof(type) * (num)); printf("REALLOC(%i) = %p\n", sizeof(type) * (num), dat);} +#define REALLOC_PTR(dat, num) {dat = realloc(dat, sizeof(void *) * (num)); printf("REALLOC_PTR(%i) = %p\n", sizeof(void *) * (num), dat);} + +#endif +#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 @@ +#include "e_str.h" +#include "e_mem.h" + +/* string manipulation conveience calls */ + +void +e_string_free_list(char **slist, int num) +{ + int i; + + for (i = 0; i < num; i++) + FREE(slist[i]); + FREE(slist); +} + +char * +e_string_dup(char *str) +{ + if (!str) + return NULL; + return strdup(str); +} + +int +e_string_cmp(char *s1, char *s2) +{ + if ((!s1) || (!s2)) + return 0; + if (!strcmp(s1, s2)) + return 1; + return 0; +} + +int +e_string_case_cmp(char *s1, char *s2) +{ + if ((!s1) || (!s2)) + return 0; + if (!strcasecmp(s1, s2)) + return 1; + return 0; +} + +int +e_string_length(char *str) +{ + return strlen(str); +} + +void +e_string_clear(char *str) +{ + str[0] = 0; +} + +void +e_string_cat(char *str, char *cat) +{ + strcat(str, cat); +} + +void +e_string_cat_n(char *str, char *cat, int start, int len) +{ + strncat(str, &(cat[start]), len); +} + +char * +e_string_escape(char *str) +{ + char buf[8192]; + int i, j, len; + + e_string_clear(buf); + len = e_string_length(str); + for (i = 0, j = 0; i < len; i++) + { + switch (str[i]) + { + case ' ': + case '"': + case '\'': + case '\\': + case '(': + case ')': + case '[': + case ']': + case '$': + case '`': + case '~': + case '!': + case '#': + case '&': + case '*': + case '?': + case '|': + case ';': + case '<': + case '>': + buf[j++] = '\\'; + buf[j++] = str[i]; + break; + default: + buf[j++] = str[i]; + break; + } + } + buf[j] = 0; + return e_string_dup(buf); +} + +char * +e_string_build(char *format, char **rep_list, int rep_num) +{ + char buf[16384], *s; + int i; + + e_string_clear(buf); + s = format; + i = 0; + while (*s) + { + if (s[0] == '%') + { + if (s[1] == '%') + e_string_cat(buf, "%"); + else + { + int j; + + for (j = 0; j < rep_num; j += 2) + { + if (s[1] == rep_list[j][0]) + { + char *ss; + + ss = e_string_escape(rep_list[j + 1]); + e_string_cat(buf, ss); + FREE(ss); + break; + } + } + } + s++; + } + else + strncat(buf, s, 1); + s++; + } + return e_string_dup(buf); +} 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 @@ +#ifndef E_STR_H +#define E_STR_H 1 + +#include +#include + +void e_string_free_list(char **slist, int num); +char *e_string_dup(char *str); +int e_string_cmp(char *s1, char *s2); +int e_string_case_cmp(char *s1, char *s2); +int e_string_length(char *str); +void e_string_clear(char *str); +void e_string_cat(char *str, char *cat); +void e_string_cat_n(char *str, char *cat, int start, int len); +char *e_string_escape(char *str); +char *e_string_build(char *format, char **rep_list, int rep_num); + +#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 @@ +#include "e_util.h" +#include "e_mem.h" +#include "e_str.h" + +static void sort_alpha_internal(char **a, int l, int r); + +double +e_get_time(void) +{ + struct timeval timev; + + gettimeofday(&timev, NULL); + return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); +} + +pid_t +e_run(char *exe) +{ + pid_t pid; + + pid = fork(); + if (pid) + return pid; + setsid(); + execl("/bin/sh", "/bin/sh", "-c", exe, NULL); + exit(0); + return 0; +} + +pid_t +e_run_in_dir(char *exe, char *dir) +{ + pid_t pid; + + pid = fork(); + if (pid) + return pid; + chdir(dir); + setsid(); + execl("/bin/sh", "/bin/sh", "-c", exe, NULL); + exit(0); + return 0; +} + +void +e_set_env(char *variable, char *content) +{ + char env[4096]; + + sprintf(env, "%s=%s", variable, content); + putenv(env); +} + +uid_t +e_user_id(void) +{ + static uid_t uid = 0xffffffff; + + if (uid != 0xffffffff) + return uid; + uid = getuid(); + return uid; +} + +gid_t +e_group_id(void) +{ + static gid_t gid = 0xffffffff; + + if (gid != 0xffffffff) + return gid; + gid = getgid(); + return gid; +} + +static void +sort_alpha_internal(char **a, int l, int r) +{ + int i, j, m; + char *v, *t; + + if (r > l) + { + m = ((r + l) >> 1) + 1; + if (strcmp(a[l], a[r]) > 0) + { + t = a[l]; + a[l] = a[r]; + a[r] = t; + } + if (strcmp(a[l], a[m]) > 0) + { + t = a[l]; + a[l] = a[m]; + a[m] = t; + } + if (strcmp(a[r], a[m]) > 0) + { + t = a[r]; + a[r] = a[m]; + a[m] = t; + } + v = a[r]; + i = l - 1; + j = r; + for (;;) + { + while (strcmp(a[++i], v) < 0); + while (strcmp(a[--j], v) > 0); + if (i >= j) + break; + t = a[i]; + a[i] = a[j]; + a[j] = t; + } + t = a[i]; + a[i] = a[r]; + a[r] = t; + sort_alpha_internal(a, l, i - 1); + sort_alpha_internal(a, i + 1, r); + } +} + +void +sort_alpha(char **list, int num) +{ + sort_alpha_internal(list, 0, num - 1); +} + +char * +e_home_dir(void) +{ + char *home; + + home = getenv("HOME"); + if (!home) + home = getenv("TMPDIR"); + if (!home) + home = "/tmp"; + return home; +} + +const char * +e_get_basename(const char *s) +{ + const char *b; + + b = strrchr(s, '/'); + return ((b) ? (++b) : (s)); +} + +void +spawn_info_window(char *path) +{ + + char runline[8192]; + char *realline; + + realline = e_string_escape(path); + sprintf(runline, "efileinfo %s", realline); + e_run(runline); + IF_FREE(realline); + +} 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 @@ +#ifndef E_UTIL_H +#define E_UTIL_H 1 + +#include +#include +#include +#include + +#ifdef EFM_DEBUG +# define D(x) do {printf(__FILE__ ":%d: ", __LINE__); printf x; fflush(stdout);} while (0) +#else +# define D(x) ((void) 0) +#endif + +#define XY_IN_RECT(x, y, rx, ry, rw, rh) \ +(((x) >= (rx)) && ((y) >= (ry)) && ((x) < ((rx) + (rw))) && ((y) < ((ry) + (rh)))) +#define CLIP(x, y, w, h, xx, yy, ww, hh) \ +if (x < (xx)) {w += (x - (xx)); x = (xx);} \ +if (y < (yy)) {h += (y - (yy)); y = (yy);} \ +if ((x + w) > ((xx) + (ww))) {w = (ww) - x;} \ +if ((y + h) > ((yy) + (hh))) {h = (hh) - y;} +#define BOUND_RECTS(cx, cy, cw, ch, x, y, w, h, d) \ +if (d) { \ +if ((x) < cx) {cw += (cx - (x)); cx = x;} \ +if ((y) < cy) {ch += (cy - (y)); cy = y;} \ +if (((x) + (w)) > (cx + cw)) cw += (((x) + (w)) - (cx + cw)); \ +if (((y) + (h)) > (cy + ch)) ch += (((y) + (h)) - (cy + ch)); } \ +else { cx = x; cy = y; cw = w; ch = h; (d) = 1; } +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define SPANS_COMMON(x1, w1, x2, w2) \ +(!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1))))) +#define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \ +((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh)))) +#define RECT_INSIDE(x, y, w, h, xx, yy, ww, hh) \ +(((xx) >= (x)) && (((xx) + (ww)) <= ((x) + (w))) && \ + ((yy) >= (y)) && (((yy) + (hh)) <= ((y) + (h)))) +#define START_LIST_DEL(type, base, cmp) \ +type *_p, *_pp; _pp = NULL; _p = (base); while(_p) { if (cmp) { \ +if (_pp) _pp->next = _p->next; else (base) = _p->next; +#define END_LIST_DEL \ +return; } _pp = _p; _p = _p->next; } +#define IC(name) e_path_find(path_icons, name) + +double e_get_time(void); +pid_t e_run(char *exe); +pid_t e_run_in_dir(char *exe, char *dir); +void e_set_env(char *variable, char *content); +uid_t e_user_id(void); +gid_t e_group_id(void); +void sort_alpha(char **list, int num); +char *e_home_dir(void); +const char *e_get_basename(const char *); +void spawn_info_window(char *path); + +#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 @@ +#include "e_x.h" +#include "e_mem.h" +#include "e_str.h" +#include +#include +#include + +typedef struct _window_list Window_List; + +struct _window_list +{ + Window win; + Window_List *next; +}; + +static Display *disp; +static Visual *default_vis; +static Colormap default_cm; +static int default_depth; +static Window default_win; +static Window default_root; + +static XContext xid_context = 0; + +static int lock_scroll = 0; +static int lock_num = 0; +static int lock_caps = 0; + +static Window focused_win = 0; + +static int mod_shift = 0; +static int mod_ctrl = 0; +static int mod_alt = 0; +static int mod_win = 0; + +static Window grabkey_win = 0; + +static int mouse_x = 0, mouse_y = 0; + +static Window current_dnd_win = 0; +static int current_dnd_target_ok = 0; + +static int x_grabs = 0; + +static Window_List *ignore_wins = NULL; + +static Window grab_pointer_win = 0; + +static int dnd_copy = 0; +static int dnd_link = 0; +static int dnd_move = 1; + +static void e_handle_x_error(Display * d, XErrorEvent * ev); +static void e_handle_x_io_error(Display * d); +static Window e_window_at_xy_0(Window base, int bx, int by, int x, int y); + +static void +e_handle_x_error(Display * d, XErrorEvent * ev) +{ + /* ignroe all X errors */ + return; + d = NULL; + ev = NULL; +} + +static void +e_handle_x_io_error(Display * d) +{ + /* FIXME: call clean exit handler */ + exit(1); + d = NULL; +} + +void +e_del_child(Window win, Window child) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + return; + if (xid) + { + int i; + + for (i = 0; i < xid->children_num; i++) + { + if (xid->children[i] == child) + { + int j; + + for (j = i; j < xid->children_num - 1; j++) + xid->children[j] = xid->children[j + 1]; + xid->children_num--; + REALLOC(xid->children, Window, xid->children_num); + return; + } + } + } +} + +void +e_add_child(Window win, Window child) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + return; + if (xid) + { + xid->children_num++; + if (!xid->children) + xid->children = NEW(Window, xid->children_num); + else + REALLOC(xid->children, Window, xid->children_num); + xid->children[xid->children_num - 1] = child; + } +} + +void +e_raise_child(Window win, Window child) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + return; + if (xid) + { + int i; + + for (i = 0; i < xid->children_num; i++) + { + if (xid->children[i] == child) + { + int j; + + for (j = i; j < xid->children_num - 1; j++) + xid->children[j] = xid->children[j + 1]; + xid->children[xid->children_num - 1] = child; + return; + } + } + } +} + +void +e_lower_child(Window win, Window child) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + return; + if (xid) + { + int i; + + for (i = 0; i < xid->children_num; i++) + { + if (xid->children[i] == child) + { + int j; + + for (j = i; j > 0; j--) + xid->children[j] = xid->children[j - 1]; + xid->children[0] = child; + return; + } + } + } +} + +E_XID * +e_add_xid(Window win, int x, int y, int w, int h, int depth, Window parent) +{ + E_XID *xid = NULL; + + e_window_add_events(win, XEV_IN_OUT | XEV_CONFIGURE | XEV_VISIBILITY); + xid = NEW(E_XID, 1); + xid->win = win; + xid->x = x; + xid->y = y; + xid->w = w; + xid->h = h; + xid->mapped = 0; + xid->depth = depth; + xid->mouse_in = 0; + xid->parent = parent; + xid->root = e_window_get_root(parent); + xid->children_num = 0; + xid->children = NULL; + XSaveContext(disp, xid->win, xid_context, (XPointer) xid); + return xid; +} + +E_XID * +e_validate_xid(Window win) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + { + XWindowAttributes att; + Window root_ret = 0, parent_ret = 0, *children_ret = NULL; + unsigned int children_ret_num = 0; + + e_window_add_events(win, XEV_IN_OUT | XEV_CONFIGURE | + XEV_VISIBILITY | XEV_CHILD_CHANGE); + xid = NEW(E_XID, 1); + xid->win = win; + if (!XGetWindowAttributes(disp, win, &att)) + { + FREE(xid); + return NULL; + } + if (!XQueryTree(disp, win, &root_ret, &parent_ret, &children_ret, + &children_ret_num)) + { + FREE(xid); + return NULL; + } + xid->parent = parent_ret; + if (xid->parent) + e_validate_xid(xid->parent); + if (children_ret) + { + xid->children_num = children_ret_num; + xid->children = NEW(Window, children_ret_num); + MEMCPY(children_ret, xid->children, Window, children_ret_num); + XFree(children_ret); + } + else + { + xid->children_num = 0; + xid->children = NULL; + } + xid->root = root_ret; + xid->x = att.x; + xid->y = att.y; + xid->w = att.width; + xid->h = att.height; + if (att.map_state == IsUnmapped) + xid->mapped = 0; + else + xid->mapped = 1; + xid->depth = att.depth; + xid->mouse_in = 0; + XSaveContext(disp, xid->win, xid_context, (XPointer) xid); + } + return xid; +} + +void +e_unvalidate_xid(Window win) +{ + E_XID *xid = NULL; + + if (XFindContext(disp, win, xid_context, (XPointer *) & xid) == XCNOENT) + return; + if (xid) + { + int i; + + for (i = 0; i < xid->children_num; i++) + e_unvalidate_xid(xid->children[i]); + IF_FREE(xid->children); + FREE(xid); + XDeleteContext(disp, win, xid_context); + } +} + +void +e_sync(void) +{ + XSync(disp, False); +} + +void +e_flush(void) +{ + XFlush(disp); +} + +Window +e_window_new(Window parent, int x, int y, int w, int h) +{ + Window win; + XSetWindowAttributes attr; + + if (!parent) + parent = default_root; + attr.backing_store = NotUseful; + attr.override_redirect = False; + attr.colormap = default_cm; + attr.border_pixel = 0; + attr.background_pixmap = None; + attr.save_under = False; + attr.do_not_propagate_mask = True; + win = XCreateWindow(disp, parent, + x, y, w, h, 0, + default_depth, InputOutput, default_vis, + CWOverrideRedirect | CWSaveUnder | CWBackingStore | + CWColormap | CWBackPixmap | CWBorderPixel | + CWDontPropagate, &attr); + e_add_xid(win, x, y, w, h, default_depth, parent); + return win; +} + +Window +e_window_override_new(Window parent, int x, int y, int w, int h) +{ + Window win; + XSetWindowAttributes attr; + + if (!parent) + parent = default_root; + attr.backing_store = NotUseful; + attr.override_redirect = True; + attr.colormap = default_cm; + attr.border_pixel = 0; + attr.background_pixmap = None; + attr.save_under = False; + attr.do_not_propagate_mask = True; + win = XCreateWindow(disp, parent, + x, y, w, h, 0, + default_depth, InputOutput, default_vis, + CWOverrideRedirect | CWSaveUnder | CWBackingStore | + CWColormap | CWBackPixmap | CWBorderPixel | + CWDontPropagate, &attr); + e_add_xid(win, x, y, w, h, default_depth, parent); + return win; +} + +Window +e_window_input_new(Window parent, int x, int y, int w, int h) +{ + Window win; + XSetWindowAttributes attr; + + if (!parent) + parent = default_root; + attr.override_redirect = True; + attr.do_not_propagate_mask = True; + win = XCreateWindow(disp, parent, + x, y, w, h, 0, + 0, InputOnly, default_vis, + CWOverrideRedirect | CWDontPropagate, &attr); + e_add_xid(win, x, y, w, h, 0, parent); + return win; +} + +void +e_window_show(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if (xid->mapped) + xid->mapped = 1; + XMapWindow(disp, win); + } +} + +void +e_window_hide(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if (!xid->mapped) + return; + xid->mapped = 0; + XUnmapWindow(disp, win); + } +} + +Pixmap +e_pixmap_new(Window win, int w, int h, int dep) +{ + if (!win) + win = default_win; + if (dep == 0) + dep = default_depth; + return XCreatePixmap(disp, win, w, h, dep); +} + +void +e_pixmap_free(Pixmap pmap) +{ + if (!pmap) + return; + XFreePixmap(disp, pmap); +} + +void +e_window_set_background_pixmap(Window win, Pixmap pmap) +{ + XSetWindowBackgroundPixmap(disp, win, pmap); +} + +void +e_window_set_shape_mask(Window win, Pixmap mask) +{ + XShapeCombineMask(disp, win, ShapeBounding, 0, 0, mask, ShapeSet); +} + +void +e_window_clear(Window win) +{ + XClearWindow(disp, win); +} + +void +e_window_clear_area(Window win, int x, int y, int w, int h) +{ + XClearArea(disp, win, x, y, w, h, False); +} + +void +e_pointer_xy(Window win, int *x, int *y) +{ + Window dw; + unsigned int dm; + int wx, wy; + + if (win == 0) + win = default_root; + XQueryPointer(disp, win, &dw, &dw, &mouse_x, &mouse_y, &wx, &wy, &dm); + if (x) + *x = wx; + if (y) + *y = wy; +} + +void +e_pointer_xy_set(int x, int y) +{ + mouse_x = x; + mouse_y = y; +} + +void +e_pointer_xy_get(int *x, int *y) +{ + if (x) + *x = mouse_x; + if (y) + *y = mouse_y; +} + +void +e_window_set_events(Window win, long mask) +{ + if (win == 0) + win = default_root; + XSelectInput(disp, win, mask); +} + +void +e_window_remove_events(Window win, long mask) +{ + XWindowAttributes att; + + if (win == 0) + win = default_root; + if (XGetWindowAttributes(disp, win, &att) == True) + { + mask = att.your_event_mask & (~mask); + e_window_set_events(win, mask); + } +} + +void +e_window_add_events(Window win, long mask) +{ + XWindowAttributes att; + + if (win == 0) + win = default_root; + if (XGetWindowAttributes(disp, win, &att) == True) + { + mask = att.your_event_mask | mask; + e_window_set_events(win, mask); + } +} + +void +e_window_move(Window win, int x, int y) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if ((xid->x == x) && (xid->y == y)) + return; + xid->x = x; + xid->y = y; + XMoveWindow(disp, win, x, y); + } +} + +void +e_window_resize(Window win, int w, int h) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if ((xid->w == w) && (xid->h == h)) + return; + xid->w = w; + xid->h = h; + XResizeWindow(disp, win, w, h); + } +} + +void +e_window_move_resize(Window win, int x, int y, int w, int h) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if ((xid->x == x) && (xid->y == y) && (xid->w == w) && (xid->h == h)) + return; + xid->x = x; + xid->y = y; + xid->w = w; + xid->h = h; + XMoveResizeWindow(disp, win, x, y, w, h); + } +} + +int +e_x_get_fd(void) +{ + return ConnectionNumber(disp); +} + +void +e_display_init(char *display) +{ + int revert; + + xid_context = XUniqueContext(); + disp = XOpenDisplay(display); + if (!disp) + { + char *d; + + d = getenv("DISPLAY"); + if (d) + fprintf(stderr, + "Fatal Error:\n" + "Cannot connect to the display nominated by your DISPLAY variable:\n" + "%s\n" + "Try changing your DISPLAY variable like:\n" + "DISPLAY=host:0 efm\n", d); + else + fprintf(stderr, + "Fatal Error:\n" + "No DISPLAY variable set so cannot determine display to connect to.\n" + "Try setting your DISPLAY variable like:\n" + "DISPLAY=host:0 efm\n"); + exit(1); + } + XSetErrorHandler((XErrorHandler) e_handle_x_error); + XSetIOErrorHandler((XIOErrorHandler) e_handle_x_io_error); + default_vis = DefaultVisual(disp, DefaultScreen(disp)); + default_depth = DefaultDepth(disp, DefaultScreen(disp)); + default_cm = DefaultColormap(disp, DefaultScreen(disp)); + default_win = DefaultRootWindow(disp); + default_root = DefaultRootWindow(disp); + mod_shift = e_mod_mask_shift_get(); + mod_ctrl = e_mod_mask_ctrl_get(); + mod_alt = e_mod_mask_alt_get(); + mod_win = e_mod_mask_win_get(); + XGetInputFocus(disp, &focused_win, &revert); + e_window_set_events(default_root, XEV_KEY | XEV_IN_OUT | XEV_MOUSE_MOVE | + XEV_CONFIGURE | XEV_CHILD_CHANGE | XEV_PROPERTY | + XEV_COLORMAP | XEV_VISIBILITY); + e_pointer_xy(0, NULL, NULL); + imlib_context_set_display(disp); + imlib_context_set_visual(default_vis); + imlib_context_set_colormap(default_cm); + imlib_context_set_drawable(default_root); + imlib_context_set_dither(0); + imlib_context_set_blend(1); +} + +int +e_events_pending(void) +{ + if (!disp) return 0; + return XPending(disp); +} + +void +e_get_next_event(XEvent * event) +{ + XNextEvent(disp, event); +} + +int +e_event_shape_get_id(void) +{ + int base = -1, err_base; + + XShapeQueryExtension(disp, &base, &err_base); + base += ShapeNotify; + return base; +} + +KeySym +e_key_get_keysym_from_keycode(KeyCode keycode) +{ + return XKeycodeToKeysym(disp, keycode, 0); +} + +char * +e_key_get_string_from_keycode(KeyCode keycode) +{ + return e_string_dup(XKeysymToString(e_key_get_keysym_from_keycode(keycode))); +} + +void +e_event_allow(int mode, Time t) +{ + XAllowEvents(disp, mode, t); +} + +int +e_lock_mask_scroll_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Scroll_Lock); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_lock_mask_num_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Num_Lock); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_lock_mask_caps_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Caps_Lock); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_mod_mask_shift_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Shift_L); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_mod_mask_ctrl_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Control_L); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_mod_mask_alt_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Alt_L); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_mod_mask_win_get(void) +{ + static int have_mask = 0; + static int mask = 0; + XModifierKeymap *mod; + KeyCode nl; + int i; + int masks[8] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, + Mod4Mask, Mod5Mask + }; + + if (have_mask) + return mask; + mod = XGetModifierMapping(disp); + nl = XKeysymToKeycode(disp, XK_Meta_L); + if ((mod) && (mod->max_keypermod > 0)) + { + for (i = 0; i < (8 * mod->max_keypermod); i++) + { + if ((nl) && (mod->modifiermap[i] == nl)) + { + mask = masks[i / mod->max_keypermod]; + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + if (mask == e_mod_mask_alt_get()) + mask = 0; + if (mask == e_mod_mask_ctrl_get()) + mask = 0; + have_mask = 1; + return mask; + } + } + } + if (mod) + { + if (mod->modifiermap) + XFree(mod->modifiermap); + XFree(mod); + } + return 0; +} + +int +e_lock_mask_get(void) +{ + static int mask = 0; + Window root_ret, child_ret; + int root_x_ret, root_y_ret, win_x_ret, win_y_ret; + unsigned int mask_ret; + + if (!mask) + mask = e_lock_mask_scroll_get() | e_lock_mask_num_get() | + e_lock_mask_caps_get(); + XQueryPointer(disp, default_root, &root_ret, &child_ret, &root_x_ret, + &root_y_ret, &win_x_ret, &win_y_ret, &mask_ret); + return (mask_ret & mask); +} + +int +e_modifier_mask_get(void) +{ + Window root_ret, child_ret; + int root_x_ret, root_y_ret, win_x_ret, win_y_ret; + unsigned int mask_ret; + + XQueryPointer(disp, default_root, &root_ret, &child_ret, &root_x_ret, + &root_y_ret, &win_x_ret, &win_y_ret, &mask_ret); + return (mask_ret); +} + +Window +e_get_key_grab_win(void) +{ + return grabkey_win; +} + +void +e_key_grab(char *key, Ev_Key_Modifiers mods, int anymod, int sync) +{ + KeyCode keycode; + int i, mod, mask_scroll, mask_num, mask_caps, masks[8], mode; + + keycode = e_key_get_keycode(key); + mod = 0; + mode = GrabModeAsync; + if (sync) + mode = GrabModeSync; + if (!grabkey_win) + grabkey_win = default_root; + if (mods & EV_KEY_MODIFIER_SHIFT) + mod |= mod_shift; + if (mods & EV_KEY_MODIFIER_CTRL) + mod |= mod_ctrl; + if (mods & EV_KEY_MODIFIER_ALT) + mod |= mod_alt; + if (mods & EV_KEY_MODIFIER_WIN) + mod |= mod_win; + mask_scroll = e_lock_mask_scroll_get(); + mask_num = e_lock_mask_num_get(); + mask_caps = e_lock_mask_caps_get(); + masks[0] = 0; + masks[1] = mask_scroll; + masks[2] = mask_num; + masks[3] = mask_caps; + masks[4] = mask_scroll | mask_num; + masks[5] = mask_scroll | mask_caps; + masks[6] = mask_num | mask_caps; + masks[7] = mask_scroll | mask_num | mask_caps; + if (anymod) + XGrabKey(disp, keycode, AnyModifier, grabkey_win, False, mode, mode); + else + { + for (i = 0; i < 8; i++) + XGrabKey(disp, keycode, masks[i] | mod, grabkey_win, False, + mode, mode); + } +} + +void +e_key_ungrab(char *key, Ev_Key_Modifiers mods, int anymod) +{ + KeyCode keycode; + + keycode = e_key_get_keycode(key); + if (anymod) + XUngrabKey(disp, keycode, AnyModifier, default_root); + else + { + int i, mod, mask_scroll, mask_num, mask_caps, masks[8]; + + mod = 0; + if (mods & EV_KEY_MODIFIER_SHIFT) + mod |= mod_shift; + if (mods & EV_KEY_MODIFIER_CTRL) + mod |= mod_ctrl; + if (mods & EV_KEY_MODIFIER_ALT) + mod |= mod_alt; + if (mods & EV_KEY_MODIFIER_WIN) + mod |= mod_win; + mask_scroll = e_lock_mask_scroll_get(); + mask_num = e_lock_mask_num_get(); + mask_caps = e_lock_mask_caps_get(); + masks[0] = 0; + masks[1] = mask_scroll; + masks[2] = mask_num; + masks[3] = mask_caps; + masks[4] = mask_scroll | mask_num; + masks[5] = mask_scroll | mask_caps; + masks[6] = mask_num | mask_caps; + masks[7] = mask_scroll | mask_num | mask_caps; + for (i = 0; i < 8; i++) + XUngrabKey(disp, keycode, masks[i] | mod, grabkey_win); + } +} + +KeyCode +e_key_get_keycode(char *key) +{ + return XKeysymToKeycode(disp, XStringToKeysym(key)); +} + +void +e_window_destroy(Window win) +{ + e_unvalidate_xid(win); + XDestroyWindow(disp, win); +} + +void +e_window_reparent(Window win, Window parent, int x, int y) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + if (parent == 0) + parent = default_root; + XReparentWindow(disp, win, parent, x, y); + e_del_child(xid->parent, win); + e_add_child(parent, win); + xid->parent = parent; + xid->x = x; + xid->y = y; + } +} + +void +e_window_raise(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + XRaiseWindow(disp, win); + e_raise_child(xid->parent, win); + } +} + +void +e_window_lower(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + { + XLowerWindow(disp, win); + e_lower_child(xid->parent, win); + } +} + +void +e_window_get_geometry(Window win, int *x, int *y, int *w, int *h) +{ + E_XID *xid = NULL; + + if (win == 0) + win = default_root; + xid = e_validate_xid(win); + if (xid) + { + if (x) + *x = xid->x; + if (y) + *y = xid->y; + if (w) + *w = xid->w; + if (h) + *h = xid->h; + } + else + { + if (x) + *x = 0; + if (y) + *y = 0; + if (w) + *w = 0; + if (h) + *h = 0; + } +} + +int +e_window_get_depth(Window win) +{ + E_XID *xid = NULL; + + if (win == 0) + win = default_root; + xid = e_validate_xid(win); + if (xid) + return xid->depth; + return -1; +} + +int +e_window_exists(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + return 1; + return 0; +} + +Window +e_window_get_parent(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + return xid->parent; + return 0; +} + +Window * +e_window_get_children(Window win, int *num) +{ + E_XID *xid = NULL; + + if (win == 0) + win = default_root; + xid = e_validate_xid(win); + if (xid) + { + Window *wlist = NULL; + + *num = xid->children_num; + if (xid->children) + { + wlist = NEW(Window, xid->children_num); + MEMCPY(xid->children, wlist, Window, xid->children_num); + } + return wlist; + } + *num = 0; + return NULL; +} + +int +e_window_mouse_in(Window win) +{ + E_XID *xid = NULL; + + if (win == 0) + win = default_root; + xid = e_validate_xid(win); + if (xid) + return xid->mouse_in; + return 0; +} + +void +e_window_mouse_set_in(Window win, int in) +{ + E_XID *xid = NULL; + + if (win == 0) + win = default_root; + xid = e_validate_xid(win); + if (xid) + xid->mouse_in = in; +} + +Display * +e_display_get(void) +{ + return disp; +} + +Window +e_window_get_root(Window win) +{ + E_XID *xid = NULL; + + xid = e_validate_xid(win); + if (xid) + return xid->root; + return 0; +} + +void +e_lock_scroll_set(int onoff) +{ + lock_scroll = onoff; +} + +int +e_lock_scroll_get(void) +{ + return lock_scroll; +} + +void +e_lock_num_set(int onoff) +{ + lock_num = onoff; +} + +int +e_lock_num_get(void) +{ + return lock_num; +} + +void +e_lock_caps_set(int onoff) +{ + lock_caps = onoff; +} + +int +e_lock_caps_get(void) +{ + return lock_caps; +} + +void +e_mod_shift_set(int onoff) +{ + mod_shift = onoff; +} + +int +e_mod_shift_get(void) +{ + return mod_shift; +} + +void +e_mod_ctrl_set(int onoff) +{ + mod_ctrl = onoff; +} + +int +e_mod_ctrl_get(void) +{ + return mod_ctrl; +} + +void +e_mod_alt_set(int onoff) +{ + mod_alt = onoff; +} + +int +e_mod_alt_get(void) +{ + return mod_alt; +} + +void +e_mod_win_set(int onoff) +{ + mod_win = onoff; +} + +int +e_mod_win_get(void) +{ + return mod_win; +} + +void +e_focus_window_set(Window win) +{ + focused_win = win; +} + +Window +e_focus_window_get(void) +{ + return focused_win; +} + +void +e_focus_to_window(Window win) +{ + if (win == 0) + win = default_root; + XSetInputFocus(disp, win, RevertToPointerRoot, CurrentTime); +} + +Atom +e_atom_get(char *name) +{ + return XInternAtom(disp, name, False); +} + +void +e_window_set_delete_inform(Window win) +{ + static Atom protocols[1] = { 0 }; + + E_ATOM(protocols[0], "WM_DELETE_WINDOW"); + XSetWMProtocols(disp, win, protocols, 1); +} + +void +e_window_property_set(Window win, Atom type, Atom format, int size, void *data, + int number) +{ + if (win == 0) + win = default_root; + if (size != 32) + XChangeProperty(disp, win, type, format, size, PropModeReplace, + (unsigned char *)data, number); + else + { + long *dat; + int i, *ptr; + + dat = NEW(long, number); + + for (ptr = (int *)data, i = 0; i < number; i++) + dat[i] = ptr[i]; + XChangeProperty(disp, win, type, format, size, PropModeReplace, + (unsigned char *)dat, number); + FREE(dat); + } +} + +void * +e_window_property_get(Window win, Atom type, Atom format, int *size) +{ + unsigned char *retval; + Atom type_ret; + unsigned long bytes_after, num_ret; + int format_ret; + void *data = NULL; + + retval = NULL; + if (win == 0) + win = default_root; + XGetWindowProperty(disp, win, type, 0, 0x7fffffffL, False, format, + &type_ret, &format_ret, &num_ret, &bytes_after, &retval); + if (retval) + { + if (format_ret == 32) + { + int i; + + *size = num_ret * sizeof(unsigned int); + + data = NEW(unsigned int, num_ret); + + for (i = 0; i < (int)num_ret; i++) + ((unsigned int *)data)[i] = ((unsigned long *)retval)[i]; + } + else if (format_ret == 16) + { + int i; + + *size = num_ret * sizeof(unsigned short); + + data = NEW(unsigned short, *size); + + for (i = 0; i < (int)num_ret; i++) + ((unsigned short *)data)[i] = ((unsigned short *)retval)[i]; + } + else if (format_ret == 8) + { + /* format_ret == 8 */ + *size = num_ret; + data = NEW(char, num_ret); + + if (data) + memcpy(data, retval, num_ret); + } + XFree(retval); + return data; + } + *size = 0; + return NULL; +} + +void +e_window_dnd_advertise(Window win) +{ + static Atom atom_xdndaware = 0; + int dnd_version = 3; + + E_ATOM(atom_xdndaware, "XdndAware"); + e_window_property_set(win, atom_xdndaware, XA_ATOM, 32, &dnd_version, 1); +} + +void +e_grab(void) +{ + x_grabs++; + if (x_grabs == 1) + XGrabServer(disp); +} + +void +e_ungrab(void) +{ + x_grabs--; + if (x_grabs == 0) + { + XUngrabServer(disp); + e_sync(); + } +} + +void +e_window_ignore(Window win) +{ + Window_List *w; + + if (win == 0) + win = default_root; + w = NEW(Window_List, 1); + w->win = win; + w->next = ignore_wins; + ignore_wins = w; +} + +void +e_window_no_ignore(Window win) +{ + Window_List *w, *pw; + + if (win == 0) + win = default_root; + for (pw = NULL, w = ignore_wins; w; pw = w, w = w->next) + { + if (w->win == win) + { + if (pw) + pw->next = w->next; + else + ignore_wins = w->next; + FREE(w); + return; + } + } +} + +int +e_window_is_ignored(Window win) +{ + Window_List *w; + + if (win == 0) + win = default_root; + for (w = ignore_wins; w; w = w->next) + { + if (w->win == win) + return 1; + } + return 0; +} + +static Window +e_window_at_xy_0(Window base, int bx, int by, int x, int y) +{ + Window *list = NULL; + XWindowAttributes att; + Window child = 0, parent_win = 0, root_win = 0; + int i; + unsigned int ww, wh, num; + int wx, wy; + + if ((!XGetWindowAttributes(disp, base, &att)) || + (att.map_state != IsViewable)) + return 0; + + wx = att.x; + wy = att.y; + ww = att.width; + wh = att.height; + + wx += bx; + wy += by; + + if (!((x >= wx) && + (y >= wy) && (x < (int)(wx + ww)) && (y < (int)(wy + wh)))) + return 0; + + if (!XQueryTree(disp, base, &root_win, &parent_win, &list, &num)) + return base; + if (list) + { + for (i = num - 1;; i--) + { + if (!e_window_is_ignored(list[i])) + { + if ((child = e_window_at_xy_0(list[i], wx, wy, x, y)) != 0) + { + XFree(list); + return child; + } + } + if (!i) + break; + } + XFree(list); + } + return base; +} + +Window +e_window_get_at_xy(int x, int y) +{ + Window child; + + e_grab(); + child = e_window_at_xy_0(default_root, 0, 0, x, y); + if (child) + { + e_ungrab(); + return child; + } + e_ungrab(); + return default_root; +} + +int +e_window_dnd_capable(Window win) +{ + static Atom atom_xdndaware = 0; + int dnd_version = 3; + int *atom_ret; + int size = 0; + + E_ATOM(atom_xdndaware, "XdndAware"); + atom_ret = e_window_property_get(win, atom_xdndaware, XA_ATOM, &size); + if ((atom_ret) && (size >= sizeof(int))) + { + if (atom_ret[0] == dnd_version) + { + FREE(atom_ret); + return 1; + } + FREE(atom_ret); + } + return 0; +} + +void +e_window_dnd_handle_motion(Window source_win, int x, int y, int dragging) +{ + static Atom atom_xdndenter = 0; + static Atom atom_xdndleave = 0; + static Atom atom_xdnddrop = 0; + static Atom atom_xdndposition = 0; + static Atom atom_xdndactioncopy = 0; + static Atom atom_xdndactionmove = 0; + static Atom atom_xdndactionlink = 0; + static Atom atom_xdndactionask = 0; + static Atom atom_text_uri_list = 0; + static Atom atom_text_plain = 0; + Window win; + XEvent xevent; + + win = e_window_get_at_xy(x, y); + while ((win) && (!e_window_dnd_capable(win))) + win = e_window_get_parent(win); + E_ATOM(atom_xdndenter, "XdndEnter"); + E_ATOM(atom_xdndleave, "XdndLeave"); + E_ATOM(atom_xdnddrop, "XdndDrop"); + E_ATOM(atom_xdndposition, "XdndPosition"); + E_ATOM(atom_xdndactioncopy, "XdndActionCopy"); + E_ATOM(atom_xdndactionmove, "XdndActionMove"); + E_ATOM(atom_xdndactionlink, "XdndActionLink"); + E_ATOM(atom_xdndactionask, "XdndActionAsk"); + E_ATOM(atom_text_uri_list, "text/uri-list"); + E_ATOM(atom_text_plain, "text/plain"); + if ((win != current_dnd_win) && (current_dnd_win)) + { + /* send leave to old dnd win */ + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.format = 32; + xevent.xclient.window = current_dnd_win; + xevent.xclient.message_type = atom_xdndleave; + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = 0; + xevent.xclient.data.l[2] = 0; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, current_dnd_win, False, 0, &xevent); + } + if (win) + { + if (win != current_dnd_win) + { + /* send enter on new win */ + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdndenter; + xevent.xclient.format = 32; + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = (3 << 24); + xevent.xclient.data.l[2] = atom_text_uri_list; + xevent.xclient.data.l[3] = atom_text_plain; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, win, False, 0, &xevent); + } + /* send position information */ + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdndposition; + xevent.xclient.format = 32; + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = (3 << 24); + xevent.xclient.data.l[2] = ((x << 16) & 0xffff0000) | (y & 0xffff); + xevent.xclient.data.l[3] = CurrentTime; + if (dnd_copy) + xevent.xclient.data.l[4] = atom_xdndactioncopy; + else if (dnd_link) + xevent.xclient.data.l[4] = atom_xdndactionlink; + else if (dnd_move) + xevent.xclient.data.l[4] = atom_xdndactionmove; + else + xevent.xclient.data.l[4] = atom_xdndactionask; + XSendEvent(disp, win, False, 0, &xevent); + } + if (!dragging) + { + if (win) + { + if (current_dnd_target_ok) + { + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdnddrop; + xevent.xclient.format = 32; + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = 0; + xevent.xclient.data.l[2] = CurrentTime; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, win, False, 0, &xevent); + } + else + { + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdndleave; + xevent.xclient.format = 32; + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = 0; + xevent.xclient.data.l[2] = 0; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, win, False, 0, &xevent); + } + } + current_dnd_target_ok = 0; + } + current_dnd_win = win; +} + +int +e_dnd_selection_convert(Window win, Window req, Atom type) +{ + static Atom atom_xdndselection = 0; + static Atom atom_jxselectionwindowproperty = 0; + + E_ATOM(atom_xdndselection, "XdndSelection"); + E_ATOM(atom_jxselectionwindowproperty, "JXSelectionWindowProperty"); + if (win == XGetSelectionOwner(disp, atom_xdndselection)) + { + XConvertSelection(disp, atom_xdndselection, type, + atom_jxselectionwindowproperty, req, CurrentTime); + return 1; + } + return 0; +} + +void * +e_dnd_selection_get(Window win, Window req, Atom type, int *size) +{ + unsigned char *data = NULL; + long bytes_read; + unsigned long remaining = 1; + + *size = 0; + bytes_read = 0; + while (remaining) + { + unsigned char *s; + Atom actual; + int format; + unsigned long count; + + s = NULL; + if (XGetWindowProperty(disp, win, type, bytes_read / 4, 0x10000, 1, + AnyPropertyType, &actual, &format, &count, + &remaining, &s) != Success) + { + /* error occured */ + XFree(s); + IF_FREE(data); + *size = 0; + return NULL; + } + if (s) + { + /* got some mroe data - append it */ + bytes_read += count; + if (!data) + data = NEW(char, bytes_read); + + else + REALLOC(data, char, bytes_read); + MEMCPY(s, data + (bytes_read - count), char, count); + + XFree(s); + } + } + *size = bytes_read; + return data; + req = 0; +} + +void +e_dnd_set_data(Window win) +{ + static int atom_xdndactioncopy = 0; + static int atom_xdndactionmove = 0; + static int atom_xdndactionlink = 0; + static int atom_xdndactionask = 0; + static Atom atom_xdndactionlist = 0; + static Atom atom_xdndselection = 0; + + E_ATOM(atom_xdndactioncopy, "XdndActionCopy"); + E_ATOM(atom_xdndactionmove, "XdndActionMove"); + E_ATOM(atom_xdndactionlink, "XdndActionLink"); + E_ATOM(atom_xdndactionask, "XdndActionAsk"); + E_ATOM(atom_xdndactionlist, "XdndActionList"); + E_ATOM(atom_xdndselection, "XdndSelection"); + if (dnd_copy) + e_window_property_set(win, atom_xdndactionlist, XA_ATOM, 32, + &atom_xdndactioncopy, 1); + else if (dnd_link) + e_window_property_set(win, atom_xdndactionlist, XA_ATOM, 32, + &atom_xdndactionlink, 1); + else if (dnd_move) + e_window_property_set(win, atom_xdndactionlist, XA_ATOM, 32, + &atom_xdndactionmove, 1); + else + e_window_property_set(win, atom_xdndactionlist, XA_ATOM, 32, + &atom_xdndactionask, 1); + XSetSelectionOwner(disp, atom_xdndselection, win, CurrentTime); +} + +void +e_dnd_send_data(Window win, Window source_win, void *data, int size, + Atom dest_atom, int plain_text) +{ + XEvent xevent; + static Atom atom_text_plain = 0; + static Atom atom_text_uri_list = 0; + static Atom atom_xdndselection = 0; + Atom target; + + E_ATOM(atom_xdndselection, "XdndSelection"); + E_ATOM(atom_text_uri_list, "text/uri-list"); + E_ATOM(atom_text_plain, "text/plain"); + target = atom_text_uri_list; + if (plain_text) + target = atom_text_plain; + e_window_property_set(win, dest_atom, target, 8, data, size); + xevent.xselection.type = SelectionNotify; + xevent.xselection.property = dest_atom; + xevent.xselection.display = disp; + xevent.xselection.requestor = win; + xevent.xselection.selection = atom_xdndselection; + xevent.xselection.target = target; + xevent.xselection.time = CurrentTime; + XSendEvent(disp, win, False, 0, &xevent); + return; + source_win = 0; +} + +void +e_dnd_set_mode_copy(void) +{ + dnd_copy = 1; + dnd_link = 0; + dnd_move = 0; +} + +void +e_dnd_set_mode_link(void) +{ + dnd_copy = 0; + dnd_link = 1; + dnd_move = 0; +} + +void +e_dnd_set_mode_move(void) +{ + dnd_copy = 0; + dnd_link = 0; + dnd_move = 1; +} + +void +e_dnd_set_mode_ask(void) +{ + dnd_copy = 0; + dnd_link = 0; + dnd_move = 0; +} + +void +e_dnd_own_selection(Window win) +{ + static Atom atom_xdndselection = 0; + static Atom atom_jxselectionwindowproperty = 0; + + E_ATOM(atom_xdndselection, "XdndSelection"); + E_ATOM(atom_jxselectionwindowproperty, "JXSelectionWindowProperty"); + + if (!XSetSelectionOwner(disp, atom_xdndselection, win, CurrentTime)) + return; +} + +void +e_dnd_send_drop(Window win, Window source_win) +{ + static Atom atom_xdnddrop = 0; + XEvent xevent; + + E_ATOM(atom_xdnddrop, "XdndDrop"); + + e_dnd_own_selection(source_win); + + memset(&xevent, 0, sizeof(xevent)); + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdnddrop; + xevent.xclient.format = 32; + + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = CurrentTime; + xevent.xclient.data.l[2] = 0; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, win, False, 0, &xevent); +} + +void +e_window_dnd_send_status_ok(Window source_win, Window win, int x, int y, int w, + int h) +{ + static Atom atom_xdndstatus = 0; + static Atom atom_xdndactioncopy = 0; + static Atom atom_xdndactionmove = 0; + static Atom atom_xdndactionlink = 0; + static Atom atom_xdndactionask = 0; + XEvent xevent; + + E_ATOM(atom_xdndstatus, "XdndStatus"); + E_ATOM(atom_xdndactioncopy, "XdndActionCopy"); + E_ATOM(atom_xdndactionmove, "XdndActionMove"); + E_ATOM(atom_xdndactionlink, "XdndActionLink"); + E_ATOM(atom_xdndactionask, "XdndActionAsk"); + memset(&xevent, 0, sizeof(xevent)); + + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdndstatus; + xevent.xclient.format = 32; + + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = 3; + xevent.xclient.data.l[2] = ((x << 16) & 0xffff0000) | (y & 0xffff); + xevent.xclient.data.l[3] = ((h << 16) & 0xffff0000) | (w & 0xffff); + if (dnd_copy) + xevent.xclient.data.l[4] = atom_xdndactioncopy; + else if (dnd_link) + xevent.xclient.data.l[4] = atom_xdndactionlink; + else if (dnd_move) + xevent.xclient.data.l[4] = atom_xdndactionmove; + else + xevent.xclient.data.l[4] = atom_xdndactionask; + XSendEvent(disp, win, False, 0, &xevent); +} + +void +e_window_dnd_send_finished(Window source_win, Window win) +{ + static Atom atom_xdndfinished = 0; + XEvent xevent; + + E_ATOM(atom_xdndfinished, "XdndFinished"); + memset(&xevent, 0, sizeof(xevent)); + + xevent.xany.type = ClientMessage; + xevent.xany.display = disp; + xevent.xclient.window = win; + xevent.xclient.message_type = atom_xdndfinished; + xevent.xclient.format = 32; + + xevent.xclient.data.l[0] = source_win; + xevent.xclient.data.l[1] = 0; + xevent.xclient.data.l[2] = 0; + xevent.xclient.data.l[3] = 0; + xevent.xclient.data.l[4] = 0; + XSendEvent(disp, win, False, 0, &xevent); +} + +void +e_window_dnd_ok(int ok) +{ + current_dnd_target_ok = ok; +} + +void +e_window_dnd_finished(void) +{ + current_dnd_win = 0; +} + +void +e_window_set_title(Window win, char *title) +{ + XStoreName(disp, win, title); +} + +void +e_window_set_name_class(Window win, char *name, char *class) +{ + XClassHint hint; + + hint.res_name = name; + hint.res_class = class; + XSetClassHint(disp, win, &hint); +} + +void +e_window_set_min_size(Window win, int w, int h) +{ + XSizeHints hints; + long ret; + + memset(&hints, 0, sizeof(XSizeHints)); + XGetWMNormalHints(disp, win, &hints, &ret); + hints.flags |= PMinSize | PSize | USSize; + hints.min_width = w; + hints.min_height = h; + XSetWMNormalHints(disp, win, &hints); +} + +void +e_window_set_max_size(Window win, int w, int h) +{ + XSizeHints hints; + long ret; + + memset(&hints, 0, sizeof(XSizeHints)); + XGetWMNormalHints(disp, win, &hints, &ret); + hints.flags |= PMaxSize | PSize | USSize; + hints.max_width = w; + hints.max_height = h; + XSetWMNormalHints(disp, win, &hints); +} + +void +e_window_set_xy_hints(Window win, int x, int y) +{ + XSizeHints hints; + long ret; + + memset(&hints, 0, sizeof(XSizeHints)); + XGetWMNormalHints(disp, win, &hints, &ret); + hints.flags |= PPosition | USPosition | PSize | USSize; + hints.x = x; + hints.y = y; + XSetWMNormalHints(disp, win, &hints); +} + +void +e_window_get_frame_size(Window win, int *l, int *r, int *t, int *b) +{ + static Atom atom_e_frame_size = 0; + int *data, size; + + E_ATOM(atom_e_frame_size, "_E_FRAME_SIZE"); + data = e_window_property_get(win, atom_e_frame_size, XA_CARDINAL, &size); + if (data) + { + if (size == (4 * sizeof(int))) + { + if (l) + *l = data[0]; + if (r) + *r = data[1]; + if (t) + *t = data[2]; + if (b) + *b = data[3]; + } + else + { + if (l) + *l = 0; + if (r) + *r = 0; + if (t) + *t = 0; + if (b) + *b = 0; + } + FREE(data); + } + else + { + if (l) + *l = 0; + if (r) + *r = 0; + if (t) + *t = 0; + if (b) + *b = 0; + } +} + +int +e_window_save_under(Window win) +{ + XSetWindowAttributes att; + XWindowAttributes gatt; + + att.save_under = True; + XChangeWindowAttributes(disp, win, CWSaveUnder, &att); + XGetWindowAttributes(disp, win, &gatt); + if (gatt.save_under == True) + return 1; + return 0; +} + +GC +e_gc_new(Drawable d) +{ + XGCValues gcv; + + if (d == 0) + d = default_root; + return XCreateGC(disp, d, 0, &gcv); +} + +void +e_gc_free(GC gc) +{ + XFreeGC(disp, gc); +} + +void +e_gc_set_fg(GC gc, int val) +{ + XSetForeground(disp, gc, val); +} + +void +e_fill_rectangle(Drawable d, GC gc, int x, int y, int w, int h) +{ + XFillRectangle(disp, d, gc, x, y, w, h); +} + +void +e_draw_rectangle(Drawable d, GC gc, int x, int y, int w, int h) +{ + XDrawRectangle(disp, d, gc, x, y, w - 1, h - 1); +} + +void +e_draw_line(Drawable d, GC gc, int x1, int y1, int x2, int y2) +{ + XDrawLine(disp, d, gc, x1, y1, x2, y2); +} + +void +e_window_hint_set_layer(Window win, int layer) +{ + static Atom atom_win_layer = 0; + + E_ATOM(atom_win_layer, "_WIN_LAYER"); + e_window_property_set(win, atom_win_layer, XA_CARDINAL, 32, &layer, 1); +} + +void +e_window_hint_set_sticky(Window win, int sticky) +{ + static Atom atom_win_state = 0; + static Atom atom_win_hints = 0; + int data; + + E_ATOM(atom_win_state, "_WIN_STATE"); + E_ATOM(atom_win_hints, "_WIN_HINTS"); + if (sticky) + { + data = ((1 << 0) | (1 << 8) | (1 << 9)); + e_window_property_set(win, atom_win_state, XA_CARDINAL, 32, &data, 1); + data = ((1 << 0) | (1 << 1) | (1 << 2)); + e_window_property_set(win, atom_win_hints, XA_CARDINAL, 32, &data, 1); + } + else + { + data = 0; + e_window_property_set(win, atom_win_state, XA_CARDINAL, 32, &data, 1); + e_window_property_set(win, atom_win_hints, XA_CARDINAL, 32, &data, 1); + } +} + +void +e_window_hint_set_borderless(Window win) +{ + static Atom atom_motif_wm_hints = 0; + int data[5]; + + E_ATOM(atom_motif_wm_hints, "_MOTIF_WM_HINTS"); + data[0] = 0x3; + data[1] = 0x0; + data[2] = 0x0; + data[3] = 0x2ada27b0; + data[4] = 0x2aabd6b0; + e_window_property_set(win, atom_motif_wm_hints, atom_motif_wm_hints, 32, + data, 5); +} + +void +e_grab_mouse(Window win, int confine, Cursor cursor) +{ + int ret; + + if (confine) + ret = XGrabPointer(disp, win, False, + XEV_BUTTON | XEV_MOUSE_MOVE | XEV_IN_OUT, + GrabModeAsync, GrabModeAsync, + win, cursor, CurrentTime); + else + ret = XGrabPointer(disp, win, False, + XEV_BUTTON | XEV_MOUSE_MOVE | XEV_IN_OUT, + GrabModeAsync, GrabModeAsync, + None, cursor, CurrentTime); + if (ret == GrabSuccess) + grab_pointer_win = win; +} + +void +e_ungrab_mouse(void) +{ + XUngrabPointer(disp, CurrentTime); + grab_pointer_win = 0; +} + +Window +e_grab_window_get(void) +{ + return grab_pointer_win; +} + +void +e_window_gravity_reset(Window win) +{ + XSetWindowAttributes att; + + att.win_gravity = NorthWestGravity; + XChangeWindowAttributes(disp, win, CWWinGravity, &att); +} + +void +e_pointer_warp_by(int dx, int dy) +{ + XWarpPointer(disp, None, None, 0, 0, 0, 0, dx, dy); +} + +void +e_pointer_warp_to(int x, int y) +{ + XWarpPointer(disp, None, default_root, 0, 0, 0, 0, x, y); +} + +void +e_gc_set_include_inferiors(GC gc) +{ + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + XChangeGC(disp, gc, GCSubwindowMode, &gcv); +} + +void +e_area_copy(Drawable src, Drawable dest, GC gc, + int sx, int sy, int sw, int sh, int dx, int dy) +{ + if (src == 0) + src = default_root; + if (dest == 0) + dest = default_root; + XCopyArea(disp, src, dest, gc, sx, sy, sw, sh, dx, dy); +} + +Window e_window_root(void) +{ + return default_root; +} + +void +e_window_get_virtual_area(Window win, int *area_x, int *area_y) +{ + static Atom atom_win_area = 0; + int *data, size; + + E_ATOM(atom_win_area, "_WIN_AREA"); + data = e_window_property_get(win, atom_win_area, XA_CARDINAL, &size); + if (data) + { + if (size == (sizeof(int) * 2)) + { + if (area_x) + *area_x = data[0]; + if (area_y) + *area_y = data[1]; + } + FREE(data); + } +} + +void +e_get_virtual_area(int *area_x, int *area_y) +{ + static Atom atom_win_area = 0; + int *data, size; + + E_ATOM(atom_win_area, "_WIN_AREA"); + data = + e_window_property_get(default_root, atom_win_area, XA_CARDINAL, &size); + if (data) + { + if (size == (sizeof(int) * 2)) + { + if (area_x) + *area_x = data[0]; + if (area_y) + *area_y = data[1]; + } + FREE(data); + } +} diff --git a/legacy/ecore/src/e_x.h b/legacy/ecore/src/e_x.h new file mode 100644 index 0000000000..8a070aefbd --- /dev/null +++ b/legacy/ecore/src/e_x.h @@ -0,0 +1,230 @@ +#ifndef E_X_H +#define E_X_H 1 + +#define XK_MISCELLANY 1 + +#include +#include +#include +#include +#include +#include +#include + +#define XEV_NONE NoEventMask +#define XEV_KEY KeyPressMask | KeyReleaseMask +#define XEV_BUTTON ButtonPressMask | ButtonReleaseMask +#define XEV_KEY_PRESS KeyPressMask +#define XEV_KEY_RELEASE KeyReleaseMask +#define XEV_BUTTON_PRESS ButtonPressMask +#define XEV_BUTTON_RELEASE ButtonReleaseMask +#define XEV_IN_OUT EnterWindowMask | LeaveWindowMask +#define XEV_MOUSE_MOVE PointerMotionMask | ButtonMotionMask +#define XEV_EXPOSE ExposureMask +#define XEV_VISIBILITY VisibilityChangeMask +#define XEV_CONFIGURE StructureNotifyMask +#define XEV_CHILD_CHANGE SubstructureNotifyMask +#define XEV_CHILD_REDIRECT SubstructureRedirectMask | ResizeRedirectMask +#define XEV_FOCUS FocusChangeMask +#define XEV_PROPERTY PropertyChangeMask +#define XEV_COLORMAP ColormapChangeMask + +typedef struct _e_xid E_XID; +typedef struct _e_keygrab E_KeyGrab; + +enum _ev_modifiers +{ + EV_KEY_MODIFIER_NONE = 0, + EV_KEY_MODIFIER_SHIFT = (1 << 0), + EV_KEY_MODIFIER_CTRL = (1 << 1), + EV_KEY_MODIFIER_ALT = (1 << 2), + EV_KEY_MODIFIER_WIN = (1 << 3) +}; + +typedef enum _ev_modifiers Ev_Key_Modifiers; + +struct _e_xid +{ + Window win; + Window parent; + Window root; + int children_num; + Window *children; + int x, y, w, h; + int mapped; + int mouse_in; + int depth; +}; + +void e_del_child(Window win, Window child); +void e_add_child(Window win, Window child); +void e_raise_child(Window win, Window child); +void e_lower_child(Window win, Window child); +E_XID *e_add_xid(Window win, int x, int y, int w, int h, int depth, + Window parent); +E_XID *e_validate_xid(Window win); +void e_unvalidate_xid(Window win); +void e_sync(void); +void e_flush(void); +Window e_window_new(Window parent, int x, int y, int w, int h); +Window e_window_override_new(Window parent, int x, int y, int w, + + int h); +Window e_window_input_new(Window parent, int x, int y, int w, + + int h); +void e_window_show(Window win); +void e_window_hide(Window win); +Pixmap e_pixmap_new(Window win, int w, int h, int dep); +void e_pixmap_free(Pixmap pmap); +void e_window_set_background_pixmap(Window win, Pixmap pmap); +void e_window_set_shape_mask(Window win, Pixmap mask); +void e_window_clear(Window win); +void e_window_clear_area(Window win, int x, int y, int w, int h); +void e_pointer_xy(Window win, int *x, int *y); +void e_pointer_xy_set(int x, int y); +void e_pointer_xy_get(int *x, int *y); +void e_window_set_events(Window win, long mask); +void e_window_remove_events(Window win, long mask); +void e_window_add_events(Window win, long mask); +void e_window_move(Window win, int x, int y); +void e_window_resize(Window win, int w, int h); +void e_window_move_resize(Window win, int x, int y, int w, + + int h); +int e_x_get_fd(void); +void e_display_init(char *display); +int e_events_pending(void); +void e_get_next_event(XEvent * event); +int e_event_shape_get_id(void); +KeySym e_key_get_keysym_from_keycode(KeyCode keycode); +char *e_key_get_string_from_keycode(KeyCode keycode); +void e_event_allow(int mode, Time t); +int e_lock_mask_scroll_get(void); +int e_lock_mask_num_get(void); +int e_lock_mask_caps_get(void); +int e_mod_mask_shift_get(void); +int e_mod_mask_ctrl_get(void); +int e_mod_mask_alt_get(void); +int e_mod_mask_win_get(void); +int e_lock_mask_get(void); +int e_modifier_mask_get(void); +Window e_get_key_grab_win(void); +void e_key_grab(char *key, Ev_Key_Modifiers mods, int anymod, + + int sync); +void e_key_ungrab(char *key, Ev_Key_Modifiers mods, int anymod); +KeyCode e_key_get_keycode(char *key); +void e_window_destroy(Window win); +void e_window_reparent(Window win, Window parent, int x, int y); +void e_window_raise(Window win); +void e_window_lower(Window win); +void e_window_get_geometry(Window win, int *x, int *y, int *w, + + int *h); +int e_window_get_depth(Window win); +int e_window_exists(Window win); +Window e_window_get_parent(Window win); +Window *e_window_get_children(Window win, int *num); +int e_window_mouse_in(Window win); +void e_window_mouse_set_in(Window win, int in); +Display *e_display_get(void); +Window e_window_get_root(Window win); +void e_lock_scroll_set(int onoff); +int e_lock_scroll_get(void); +void e_lock_num_set(int onoff); +int e_lock_num_get(void); +void e_lock_caps_set(int onoff); +int e_lock_caps_get(void); +void e_mod_shift_set(int onoff); +int e_mod_shift_get(void); +void e_mod_ctrl_set(int onoff); +int e_mod_ctrl_get(void); +void e_mod_alt_set(int onoff); +int e_mod_alt_get(void); +void e_mod_win_set(int onoff); +int e_mod_win_get(void); +void e_focus_window_set(Window win); +Window e_focus_window_get(void); +void e_focus_to_window(Window win); +Atom e_atom_get(char *name); +void e_window_set_delete_inform(Window win); +void e_window_property_set(Window win, Atom type, Atom format, + int size, void *data, int number); +void *e_window_property_get(Window win, Atom type, Atom format, + + int *size); +void e_window_dnd_advertise(Window win); +void e_grab(void); +void e_ungrab(void); +void e_window_ignore(Window win); +void e_window_no_ignore(Window win); +int e_window_is_ignored(Window win); +Window e_window_get_at_xy(int x, int y); +int e_window_dnd_capable(Window win); +void e_window_dnd_handle_motion(Window source_win, int x, int y, + + int dragging); +int e_dnd_selection_convert(Window win, Window req, Atom type); +void *e_dnd_selection_get(Window win, Window req, Atom type, + + int *size); +void e_window_dnd_ok(int ok); +void e_window_dnd_finished(void); +void e_window_dnd_send_status_ok(Window source_win, Window win, + int x, int y, int w, int h); +void e_window_dnd_send_finished(Window source_win, Window win); +void e_dnd_set_data(Window win); +void e_dnd_send_data(Window win, Window source_win, void *data, + int size, Atom dest_atom, int plain_text); +void e_window_set_title(Window win, char *title); +void e_window_set_name_class(Window win, char *name, + + char *class); +void e_window_set_min_size(Window win, int w, int h); +void e_window_set_max_size(Window win, int w, int h); +void e_window_set_xy_hints(Window win, int x, int y); +void e_window_get_frame_size(Window win, int *l, int *r, int *t, + + int *b); +int e_window_save_under(Window win); +GC e_gc_new(Drawable d); +void e_gc_free(GC gc); +void e_gc_set_fg(GC gc, int val); +void e_fill_rectangle(Drawable d, GC gc, int x, int y, int w, + + int h); +void e_draw_rectangle(Drawable d, GC gc, int x, int y, int w, + + int h); +void e_draw_line(Drawable d, GC gc, int x1, int y1, int x2, + + int y2); +void e_window_hint_set_layer(Window win, int layer); +void e_window_hint_set_sticky(Window win, int sticky); +void e_window_hint_set_borderless(Window win); +void e_grab_mouse(Window win, int confine, Cursor cursor); +void e_ungrab_mouse(void); +Window e_grab_window_get(void); +void e_dnd_set_mode_copy(void); +void e_dnd_set_mode_link(void); +void e_dnd_set_mode_move(void); +void e_dnd_set_mode_ask(void); +void e_dnd_own_selection(Window win); +void e_dnd_send_drop(Window win, Window source_win); +void e_window_gravity_reset(Window win); +void e_pointer_warp_by(int dx, int dy); +void e_pointer_warp_to(int x, int y); +void e_gc_set_include_inferiors(GC gc); +void e_area_copy(Drawable src, Drawable dest, GC gc, + int sx, int sy, int sw, int sh, int dx, int dy); +Window e_window_root(void); +void e_window_get_virtual_area(Window win, int *area_x, + + int *area_y); +void e_get_virtual_area(int *area_x, int *area_y); + +#define E_ATOM(atom, name) \ +if (!atom) atom = e_atom_get(name); + +#endif