Create interface to system bell
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 16 Jul 2010 20:54:18 +0000 (20:54 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 16 Jul 2010 20:54:18 +0000 (20:54 +0000)
Only the xlib implementation is done. It's calling XBell() to alert user.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@50290 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore_x/Ecore_X.h
src/lib/ecore_x/xcb/ecore_xcb.c
src/lib/ecore_x/xlib/ecore_x.c
src/tests/Makefile.am
src/tests/ecore_test_ecore.c

index 7c6f6c8..3af13c7 100644 (file)
@@ -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);
 
index 7e08484..f4f5996 100644 (file)
@@ -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
index edf7a94..e3ccfe4 100644 (file)
@@ -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__)
 {
index 8a58b0a..60ec31d 100644 (file)
@@ -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
index 02e9c6b..364eb1a 100644 (file)
@@ -2,12 +2,12 @@
 # include <config.h>
 #endif
 
+#include "ecore_suite.h"
+
 #include <Ecore.h>
 #include <Eina.h>
 #include <unistd.h>
-
-#include "ecore_suite.h"
-
+#include <stdio.h>
 
 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
 }