From 01d20339dd24d9a7405a1a7e229938146a81c90e Mon Sep 17 00:00:00 2001 From: Lucas De Marchi 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. SVN revision: 50290 --- legacy/ecore/src/lib/ecore_x/Ecore_X.h | 1 + legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c | 9 ++++++ legacy/ecore/src/lib/ecore_x/xlib/ecore_x.c | 24 ++++++++++++++ legacy/ecore/src/tests/Makefile.am | 5 +++ legacy/ecore/src/tests/ecore_test_ecore.c | 33 ++++++++++++++++++-- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_x/Ecore_X.h b/legacy/ecore/src/lib/ecore_x/Ecore_X.h index 7c6f6c8661..3af13c7df6 100644 --- a/legacy/ecore/src/lib/ecore_x/Ecore_X.h +++ b/legacy/ecore/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/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c index 7e084848ed..f4f59966d1 100644 --- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c +++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c @@ -888,6 +888,15 @@ ecore_x_kill(Ecore_X_Window window) xcb_kill_client(_ecore_xcb_conn, 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 */ diff --git a/legacy/ecore/src/lib/ecore_x/xlib/ecore_x.c b/legacy/ecore/src/lib/ecore_x/xlib/ecore_x.c index edf7a943ff..e3ccfe46ab 100644 --- a/legacy/ecore/src/lib/ecore_x/xlib/ecore_x.c +++ b/legacy/ecore/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/legacy/ecore/src/tests/Makefile.am b/legacy/ecore/src/tests/Makefile.am index 8a58b0a61d..60ec31da87 100644 --- a/legacy/ecore/src/tests/Makefile.am +++ b/legacy/ecore/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/legacy/ecore/src/tests/ecore_test_ecore.c b/legacy/ecore/src/tests/ecore_test_ecore.c index 02e9c6b37d..364eb1a695 100644 --- a/legacy/ecore/src/tests/ecore_test_ecore.c +++ b/legacy/ecore/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 }