From 154246bafbed69bb7d5ec9596d4fa4a93c743430 Mon Sep 17 00:00:00 2001 From: lucas Date: Fri, 16 Jul 2010 20:54:18 +0000 Subject: [PATCH] Create interface to system bell Only the xlib implementation is done. It's calling XBell() to alert user. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@50290 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/ecore_x/Ecore_X.h | 1 + src/lib/ecore_x/xcb/ecore_xcb.c | 9 +++++++++ src/lib/ecore_x/xlib/ecore_x.c | 24 ++++++++++++++++++++++++ src/tests/Makefile.am | 5 +++++ src/tests/ecore_test_ecore.c | 33 ++++++++++++++++++++++++++++++--- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/lib/ecore_x/Ecore_X.h b/src/lib/ecore_x/Ecore_X.h index 7c6f6c8..3af13c7 100644 --- a/src/lib/ecore_x/Ecore_X.h +++ b/src/lib/ecore_x/Ecore_X.h @@ -1074,6 +1074,7 @@ EAPI void ecore_x_sync(void); EAPI void ecore_x_killall(Ecore_X_Window root); EAPI void ecore_x_kill(Ecore_X_Window win); EAPI int ecore_x_dpi_get(void); +EAPI Eina_Bool ecore_x_bell(int percent); EAPI Ecore_X_Time ecore_x_current_time_get(void); diff --git a/src/lib/ecore_x/xcb/ecore_xcb.c b/src/lib/ecore_x/xcb/ecore_xcb.c index 7e08484..f4f5996 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb.c +++ b/src/lib/ecore_x/xcb/ecore_xcb.c @@ -889,6 +889,15 @@ ecore_x_kill(Ecore_X_Window window) } /** + * TODO: Invoke the standard system beep to alert users + */ +EAPI Eina_Bool +ecore_x_bell(int percent) +{ + return 0; +} + +/** * Return the last event time */ EAPI Ecore_X_Time diff --git a/src/lib/ecore_x/xlib/ecore_x.c b/src/lib/ecore_x/xlib/ecore_x.c index edf7a94..e3ccfe4 100644 --- a/src/lib/ecore_x/xlib/ecore_x.c +++ b/src/lib/ecore_x/xlib/ecore_x.c @@ -823,6 +823,30 @@ ecore_x_dpi_get(void) return (((s->width * 254) / s->mwidth) + 5) / 10; } +/** + * Invoke the standard system beep to alert users + * + * @param percent The volume at which the bell rings. Must be in the range + * [-100,+100]. If percent >= 0, the final volume will be: + * base - [(base * percent) / 100] + percent + * Otherwise, it's calculated as: + * base + [(base * percent) / 100] + * where @c base is the bell's base volume as set by XChangeKeyboardControl(3). + * + * @returns EINA_TRUE on success, EINA_FALSE otherwise. + */ +EAPI Eina_Bool +ecore_x_bell(int percent) +{ + int ret; + + ret = XBell(_ecore_x_disp, percent); + if (ret == BadValue) + return EINA_FALSE; + + return EINA_TRUE; +} + static Eina_Bool _ecore_x_fd_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__) { diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 8a58b0a..60ec31d 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -22,6 +22,11 @@ ecore_suite_LDADD = \ $(top_builddir)/src/lib/ecore/libecore.la \ $(top_builddir)/src/lib/ecore_con/libecore_con.la +if BUILD_ECORE_X +ecore_suite_LDADD += \ +$(top_builddir)/src/lib/ecore_x/libecore_x.la +endif + endif EXTRA_DIST = ecore_suite.h diff --git a/src/tests/ecore_test_ecore.c b/src/tests/ecore_test_ecore.c index 02e9c6b..364eb1a 100644 --- a/src/tests/ecore_test_ecore.c +++ b/src/tests/ecore_test_ecore.c @@ -2,12 +2,12 @@ # include #endif +#include "ecore_suite.h" + #include #include #include - -#include "ecore_suite.h" - +#include static int _log_dom; #define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) @@ -340,6 +340,28 @@ START_TEST(ecore_test_ecore_main_loop_event_recursive) } END_TEST +/* TODO: change to HAVE_ECORE_X when xcb implementation is done */ +#ifdef HAVE_ECORE_X_XLIB + +START_TEST(ecore_test_ecore_x_bell) +{ + int ret = 0, i; + ecore_x_init(NULL); + + printf("You should hear 3 beeps now.\n"); + for (i=0; i < 3; i++) + { + ret = ecore_x_bell(0); + fail_if(ret != EINA_TRUE); + ecore_x_sync(); + sleep(1); + } + ecore_x_shutdown(); +} +END_TEST + +#endif + void ecore_test_ecore(TCase *tc) { tcase_add_test(tc, ecore_test_ecore_init); @@ -352,4 +374,9 @@ void ecore_test_ecore(TCase *tc) tcase_add_test(tc, ecore_test_ecore_main_loop_event); tcase_add_test(tc, ecore_test_ecore_main_loop_timer_inner); tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive); + +/* TODO: change to HAVE_ECORE_X when xcb implementation is done */ +#ifdef HAVE_ECORE_X_XLIB + tcase_add_test(tc, ecore_test_ecore_x_bell); +#endif } -- 2.7.4