{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_MEDIA");
- grab_result = utilx_grab_key(disp, win, KEY_MEDIA, EXCLUSIVE_GRAB);
+ grab_result = utilx_grab_key(disp, win, symbol, EXCLUSIVE_GRAB);
if( grab_result == 0 )
{
dts_pass("utilx_grab_key", "passed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_MEDIA);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
}
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(disp, win, KEY_STOPCD, TOP_POSITION_GRAB);
+ grab_result = utilx_grab_key(disp, win, symbol, TOP_POSITION_GRAB);
if( grab_result == 0 )
{
dts_pass("utilx_grab_key", "passed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(disp, win, KEY_STOPCD, SHARED_GRAB);
+ grab_result = utilx_grab_key(disp, win, symbol, SHARED_GRAB);
if( grab_result == 0 )
{
dts_pass("utilx_grab_key", "passed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
}
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(NULL, win, KEY_STOPCD, EXCLUSIVE_GRAB);
+ grab_result = utilx_grab_key(NULL, win, symbol, EXCLUSIVE_GRAB);
if( grab_result != 0 )
{
dts_pass("utilx_grab_key", "passed");
else
{
dts_fail("utilx_grab_key", "failed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(NULL, win, KEY_STOPCD, TOP_POSITION_GRAB);
+ grab_result = utilx_grab_key(NULL, win, symbol, TOP_POSITION_GRAB);
if( grab_result != 0 )
{
dts_pass("utilx_grab_key", "passed");
else
{
dts_fail("utilx_grab_key", "failed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(NULL, win, KEY_STOPCD, SHARED_GRAB);
+ grab_result = utilx_grab_key(NULL, win, symbol, SHARED_GRAB);
if( grab_result != 0 )
{
dts_pass("utilx_grab_key", "passed");
else
{
dts_fail("utilx_grab_key", "failed");
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if( ungrab_result != 0)
dts_fail("utilx_grab_key", "ungrab failed");
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- grab_result = utilx_grab_key(disp, win, KEY_STOPCD, SHARED_GRAB);
+ grab_result = utilx_grab_key(disp, win, symbol, SHARED_GRAB);
if( grab_result != 0 ){
dts_fail("utilx_ungrab_key", "failed to grab the key");
}
- ungrab_result = utilx_ungrab_key(disp, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(disp, win, symbol);
if(ungrab_result == 0)
{
dts_pass("utilx_ungrab_key", "passed");
{
int grab_result;
int ungrab_result;
+ const char *symbol = utilx_get_key_symbol("KEY_STOPCD");
- ungrab_result = utilx_ungrab_key(NULL, win, KEY_STOPCD);
+ ungrab_result = utilx_ungrab_key(NULL, win, symbol);
if(ungrab_result != 0)
{
dts_pass("utilx_ungrab_key", "passed");
Utilx_Notification_Level utilx_get_system_notification_level (Display* dpy, Window win);
/**
- * @brief Grabs the key specfied by @a key_name for a window in the @a grab_mode.
+ * @brief Gets the string list and count of available key-names to grab.
+ * @details This function returns the newly-allocated list and count of available key-names to grab for a target device.
+ * The key-name is unchangeable whatever you develope in different target.
+ * However, key-symbol got by utilx_get_key_symbol() is changeable in different target.
+ * @since_tizen 3.0
+ * @remarks You should free the pointer of name list by free() to avoid memory-leak
+ * @param[out] count The number of avaiable keys for a target device
+ * @return newly-allocated list of available key strings, otherwise NULL.
+ * @see utilx_get_key_symbol()
+ * @par Example
+ @code
+
+ #include <utilX.h>
+
+ int
+ main (int argc, char* argv[])
+ {
+ const char **names;
+ int count = 0;
+ int i;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ exit (-1);
+
+ for (i = 0; i < count; i++)
+ {
+ const char *symbol = utilx_get_key_symbol (names[i]);
+ printf ("name: %s, symbol: %s\n", names[i], symbol);
+ }
+
+ //should free names
+ free (names);
+
+ return 0;
+ }
+
+ @endcode
+ */
+const char** utilx_get_available_key_names (int *count);
+
+/**
+ * @brief Gets a key-symbol string for a available key-name string to grab.
+ * @details This function returns a key-symbol string for a available key-name to grab for a target device.
+ * The key-name got by utilx_get_available_key_names() is unchangeable whatever you develope in different target.
+ * However, key-symbol is changeable in different target.
+ * @since_tizen 3.0
+ * @param[in] key_name The name of a key got by utilx_get_available_key_names()
+ * @return key-symbol string if success, otherwise NULL.
+ * @see utilx_get_available_key_names(), utilx_grab_key(), utilx_ungrab_key()
+ * @par Example
+ @code
+
+ #include <utilX.h>
+
+ int
+ main (int argc, char* argv[])
+ {
+ const char **names;
+ int count = 0;
+ int i;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ exit (-1);
+
+ for (i = 0; i < count; i++)
+ {
+ const char *symbol = utilx_get_key_symbol (names[i]);
+ printf ("name: %s, symbol: %s\n", names[i], symbol);
+ }
+
+ //should free names
+ free (names);
+
+ return 0;
+ }
+
+ @endcode
+ */
+const char* utilx_get_key_symbol (const char *key_name);
+
+/**
+ * @brief Grabs the key specfied by @a key_symbol for a window in the @a grab_mode.
*
* @details This function establishes a grab of the specified key for the specified window.\n
* Once a key is grabbed, all events originating from the key will only be reported to the specfied window.\n
* A trial for choosing a proper grab mode will be needed.
* @param[in] dpy The connection to the X server
* @param[in] win The window to grab a key
- * @param[in] key_name The name of a key in the string (ex> #KEY_VOLUMEUP, #KEY_VOLUMEDOWN, #KEY_SEND, and so on)
+ * @param[in] key_symbol The symbol of a key in the string
* @param[in] grab_mode The grab mode (such as #EXCLUSIVE_GRAB, #TOP_POSITION_GRAB, and #SHARED_GRAB)
* @return @c 0 on success,
* otherwise failure
* @pre This API must be called after the window 'win' has been mapped.
* @post This API adds/changes the window property related to the grabbed key.
- * @see utilx_ungrab_key()
+ * @see utilx_ungrab_key(), utilx_get_available_key_names(), utilx_get_key_symbol()
* @par Example (using X11 APIs)
@code
-
- // EXCLUSIVE_GRAB //
-
#include <X11/Xlib.h>
#include <utilX.h>
- int main()
- {
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- int grab_result;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
-
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- grab_result = utilx_grab_key(disp, w, KEY_POWER, EXCLUSIVE_GRAB);
- if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
- return -1;
- break;
- }
- ...
- }
- ...
+ static const char* key_symbol;
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
+ static int
+ get_key_symbol (void)
+ {
+ const char **names;
+ int i, count = 0;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ return 0;
+
+ for (i = 0; i < count; i++)
+ if (!strcmp (names[i], "KEY_UP"))
+ {
+ key_symbol = utilx_get_key_symbol ("KEY_UP");
+ printf ("found: key(%s,%s)\n", "KEY_UP", key_symbol);
+ free (names); // should free
+ return 1;
+ }
+
+ free (names); // should free
+ return 0;
}
- // TOP_POSITION_GRAB //
-
- #include <X11/Xlib.h>
- #include <utilX.h>
-
int main()
{
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
+ Display *disp = XOpenDisplay(NULL);
+ XEvent e;
+ int grab_result;
+ Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(disp,0), WhitePixel(disp,0));
+ XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask | ExposureMask);
+ XMapWindow(disp, w);
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- utilx_grab_key(disp, w, KEY_POWER, TOP_POSITION_GRAB);
- break;
- }
- ...
- }
- ...
+ if (!get_key_symbol ())
+ return -1;
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
- }
+ while(1)
+ {
+ XNextEvent(disp, &e);
- // SHARED_GRAB //
+ switch(e.type)
+ {
+ case MapNotify:
+ //EXCLUSIVE_GRAB
+ grab_result = utilx_grab_key(disp, w, key_symbol, EXCLUSIVE_GRAB);
+ if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
+ return -1;
- #include <X11/Xlib.h>
- #include <utilX.h>
+ //utilx_grab_key(disp, w, key_symbol, TOP_POSITION_GRAB);
+ //utilx_grab_key(disp, w, key_symbol, SHARED_GRAB);
- int main()
- {
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
+ break;
+ }
+ ...
+ }
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- utilx_grab_key(disp, w, KEY_POWER, SHARED_GRAB);
- break;
- }
- ...
- }
- ...
+ ...
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
- }
+ utilx_ungrab_key(disp, w, key_symbol);
+ return 0;
+ }
@endcode
* @par Example (using EFL APIs)
@code
-
- // EXCLUSIVE_GRAB //
-
#include <utilX.h>
#include <Ecore_Evas.h>
#include <Ecore_X.h>
- int main()
- {
- ...
-
- Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
-
- int grab_result = utilx_grab_key(disp, win, KEY_POWER, EXCLUSIVE_GRAB);
- if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
- return -1;
-
- ...
+ static const char* key_symbol;
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
- return 0;
+ static int
+ get_key_symbol (void)
+ {
+ const char **names;
+ int i, count = 0;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ return 0;
+
+ for (i = 0; i < count; i++)
+ if (!strcmp (names[i], "KEY_UP"))
+ {
+ key_symbol = utilx_get_key_symbol ("KEY_UP");
+ printf ("found: key(%s,%s)\n", "KEY_UP", key_symbol);
+ free (names); // should free
+ return 1;
+ }
+
+ free (names); // should free
+ return 0;
}
- // TOP_POSITION_GRAB //
-
- #include <utilX.h>
- #include <Ecore_Evas.h>
- #include <Ecore_X.h>
-
int main()
{
...
Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
-
- utilx_grab_key(disp, win, KEY_POWER, TOP_POSITION_GRAB);
-
- ...
+ Ecore_X_Window w = ecore_evas_software_x11_window_get(ee);
+ int grab_result;
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
- return 0;
- }
+ get_key_symbol ();
- // SHARED_GRAB //
+ //EXCLUSIVE_GRAB
+ grab_result = utilx_grab_key(disp, w, key_symbol, EXCLUSIVE_GRAB);
+ if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
+ return -1;
- #include <utilX.h>
- #include <Ecore_Evas.h>
- #include <Ecore_X.h>
+ //utilx_grab_key(disp, w, key_symbol, TOP_POSITION_GRAB);
+ //utilx_grab_key(disp, w, key_symbol, SHARED_GRAB);
- int main()
- {
...
- Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
-
- utilx_grab_key(disp, win, KEY_POWER, SHARED_GRAB);
-
- ...
+ utilx_ungrab_key(disp, w, key_symbol); //Ungrab whenever a user wants to
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
return 0;
}
@endcode
*/
-int utilx_grab_key (Display* dpy, Window win, const char* key_name, int grab_mode);
+int utilx_grab_key (Display* dpy, Window win, const char* key_symbol, int grab_mode);
/**
- * @brief Ungrabs the key specfied by @a key_name for a window.
+ * @brief Ungrabs the key specfied by @a key_symbol for a window.
*
* @details This function releases the already established grab of the specfied key for the specified window.\n
* Once the grab of the key is released, delivery of the key events for the specfied window is going to be stopped.
* @since_tizen 2.3
* @param[in] dpy The connection to the X server
* @param[in] win The window to grab a key
- * @param[in] key_name The name of a key in the string (ex> #KEY_VOLUMEUP, #KEY_VOLUMEDOWN, #KEY_SEND, and so on)
+ * @param[in] key_symbol The symbol of a key in the string got by utilx_get_key_symbol()
* @return @c 0 on success,
* otherwise failure
* @pre This API must be called after the window 'win' is mapped.
* @post This API changes/removes the window property related to the grabbed key.
- * @see utilx_grab_key()
+ * @see utilx_grab_key(), utilx_get_available_key_names(), utilx_get_key_symbol()
* @par Example (using X11 APIs)
@code
-
- // EXCLUSIVE_GRAB //
-
#include <X11/Xlib.h>
#include <utilX.h>
- int main()
- {
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- int grab_result;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
-
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- grab_result = utilx_grab_key(disp, w, KEY_POWER, EXCLUSIVE_GRAB);
- if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
- return -1;
- break;
- }
- ...
- }
- ...
+ static const char* key_symbol;
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
+ static int
+ get_key_symbol (void)
+ {
+ const char **names;
+ int i, count = 0;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ return 0;
+
+ for (i = 0; i < count; i++)
+ if (!strcmp (names[i], "KEY_UP"))
+ {
+ key_symbol = utilx_get_key_symbol ("KEY_UP");
+ printf ("found: key(%s,%s)\n", "KEY_UP", key_symbol);
+ free (names); // should free
+ return 1;
+ }
+
+ free (names); // should free
+ return 0;
}
- // TOP_POSITION_GRAB //
-
- #include <X11/Xlib.h>
- #include <utilX.h>
-
int main()
{
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
+ Display *disp = XOpenDisplay(NULL);
+ XEvent e;
+ int grab_result;
+ Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(disp,0), WhitePixel(disp,0));
+ XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask | ExposureMask);
+ XMapWindow(disp, w);
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- utilx_grab_key(disp, w, KEY_POWER, TOP_POSITION_GRAB);
- break;
- }
- ...
- }
- ...
+ if (!get_key_symbol ())
+ return -1;
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
- }
+ while(1)
+ {
+ XNextEvent(disp, &e);
- // SHARED_GRAB //
+ switch(e.type)
+ {
+ case MapNotify:
+ //EXCLUSIVE_GRAB
+ grab_result = utilx_grab_key(disp, w, key_symbol, EXCLUSIVE_GRAB);
+ if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
+ return -1;
- #include <X11/Xlib.h>
- #include <utilX.h>
+ //utilx_grab_key(disp, w, key_symbol, TOP_POSITION_GRAB);
+ //utilx_grab_key(disp, w, key_symbol, SHARED_GRAB);
- int main()
- {
- Display *disp = XOpenDisplay(NULL);
- XEvent e;
- Window w = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 5,5, 470, 780, 2, BlackPixel(d,0), WhitePixel(d,0));
- XSelectInput(disp, w, StructureNotifyMask | KeyPressMask | KeyReleaseMask);
- XMapWindow(disp, w);
+ break;
+ }
+ ...
+ }
- while(1)
- {
- XNextEvent(disp, &e);
- switch(e.type)
- {
- case MapNotify:
- utilx_grab_key(disp, w, KEY_POWER, SHARED_GRAB);
- break;
- }
- ...
- }
- ...
+ ...
- utilx_ungrab_key(disp, win, KEY_POWER);
- return 0;
- }
+ utilx_ungrab_key(disp, w, key_symbol);
+ return 0;
+ }
@endcode
* @par Example (using EFL APIs)
@code
-
- // EXCLUSIVE_GRAB //
-
#include <utilX.h>
#include <Ecore_Evas.h>
#include <Ecore_X.h>
- int main()
- {
- ...
-
- Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
+ static const char* key_symbol;
- int grab_result = utilx_grab_key(disp, win, KEY_POWER, EXCLUSIVE_GRAB);
- if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
- return -1;
- ...
-
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
- return 0;
+ static int
+ get_key_symbol (void)
+ {
+ const char **names;
+ int i, count = 0;
+
+ names = utilx_get_available_key_names (&count);
+ if (!names)
+ return 0;
+
+ for (i = 0; i < count; i++)
+ if (!strcmp (names[i], "KEY_UP"))
+ {
+ key_symbol = utilx_get_key_symbol ("KEY_UP");
+ printf ("found: key(%s,%s)\n", "KEY_UP", key_symbol);
+ free (names); // should free
+ return 1;
+ }
+
+ free (names); // should free
+ return 0;
}
- // TOP_POSITION_GRAB //
-
- #include <utilX.h>
- #include <Ecore_Evas.h>
- #include <Ecore_X.h>
-
int main()
{
...
Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
-
- utilx_grab_key(disp, win, KEY_POWER, TOP_POSITION_GRAB);
-
- ...
-
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
+ Ecore_X_Window w = ecore_evas_software_x11_window_get(ee);
+ int grab_result;
- return 0;
- }
+ get_key_symbol ();
- // SHARED_GRAB //
+ //EXCLUSIVE_GRAB
+ grab_result = utilx_grab_key(disp, w, key_symbol, EXCLUSIVE_GRAB);
+ if( EXCLUSIVE_GRABBED_ALREADY == grab_result )
+ return -1;
- #include <utilX.h>
- #include <Ecore_Evas.h>
- #include <Ecore_X.h>
+ //utilx_grab_key(disp, w, key_symbol, TOP_POSITION_GRAB);
+ //utilx_grab_key(disp, w, key_symbol, SHARED_GRAB);
- int main()
- {
...
- Ecore_X_Display* disp = ecore_x_display_get();
- Ecore_X_Window win = ecore_evas_software_x11_window_get(ee);
-
- utilx_grab_key(disp, win, KEY_POWER, SHARED_GRAB);
-
- ...
+ utilx_ungrab_key(disp, w, key_symbol); //Ungrab whenever a user wants to
- utilx_ungrab_key(disp, win, KEY_POWER);//Ungrab whenever a user wants to
return 0;
}
@endcode
*/
-int utilx_ungrab_key (Display* dpy, Window win, const char* key_name);
+int utilx_ungrab_key (Display* dpy, Window win, const char* key_symbol);
/**
* @brief Sets the window's opaque state.
#include <X11/extensions/Xvproto.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/XShm.h>
+#include <X11/Xresource.h>
#include <xf86drm.h>
#include <tbm_bufmgr.h>
#include <dri2.h>
-
#define UTILX_DEBUG 0
#if UTILX_DEBUG
#define UTILX_TRACE printf
return result;
}
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc/"
+#endif
+#define KEYMAP_FILE SYSCONFDIR"/X11/xkeysymbol.map"
+#define is_space(c) ((c)==' '||(c)=='\t'||(c) =='\n')
+
+typedef struct _Symbol_Entry
+{
+ char name[64];
+ char symbol[64];
+ XrmQuark quark;
+ struct _Symbol_Entry *next;
+} Symbol_Entry;
+
+static Symbol_Entry *symbol_list;
+static int symbol_list_len;
+
+static char*
+_utilx_strip_whitespace(char *s)
+{
+ int i;
+
+ while (s[0] && is_space(s[0]))
+ s++;
+
+ i = strlen(s) - 1;
+ while (i >= 0 && is_space(s[i]))
+ s[i--] = 0;
+
+ return s;
+}
+
+static int
+_utilx_check_key_symbol_list (char *path)
+{
+ FILE *f;
+ char *stripped, *comma, *key, *value;
+ char buf[256];
+ int line;
+ Symbol_Entry *cursor;
+
+ if (symbol_list)
+ return 1;
+
+ f = fopen(path, "r");
+ if (!f) {
+ fprintf (stderr, "[utilx] '%s' open failed: %s\n", path, strerror(errno));
+ return 0;
+ }
+
+ line = 0;
+ symbol_list_len = 0;
+
+ cursor = NULL;
+ while (fgets(buf, sizeof(buf), f)) {
+ Symbol_Entry *entry;
+
+ line++;
+
+ stripped = _utilx_strip_whitespace (buf);
+ if (stripped[0] == '#' || stripped[0] == 0)
+ continue;
+
+ comma = strchr(stripped, ',');
+ if (!comma)
+ {
+ fprintf(stderr, "[utilx] Syntax error at %s line %d\n", path, line);
+ continue;
+ }
+
+ *comma = 0;
+ key = _utilx_strip_whitespace (stripped);
+ value = _utilx_strip_whitespace (comma + 1);
+ if (!key[0])
+ {
+ fprintf (stderr, "[utilx] Missing key at %s line %d\n", path, line);
+ continue;
+ }
+ if (!value[0])
+ {
+ fprintf (stderr, "[utilx] Missing value at %s line %d\n", path, line);
+ continue;
+ }
+
+ entry = calloc (1, sizeof (Symbol_Entry));
+ if (!entry)
+ continue;
+
+ symbol_list_len++;
+
+ if (!symbol_list)
+ cursor = symbol_list = entry;
+ else if (cursor)
+ {
+ cursor->next = entry;
+ cursor = entry;
+ }
+
+ snprintf (entry->name, sizeof (entry->name), "%s", key);
+ snprintf (entry->symbol, sizeof (entry->symbol), "%s", value);
+
+ entry->quark = XrmStringToQuark (key);
+ }
+
+ fclose(f);
+
+ return 1;
+}
+
+API const char** utilx_get_available_key_names (int *count)
+{
+ char **names;
+ Symbol_Entry *entry;
+ int i;
+
+ if (!count)
+ {
+ fprintf(stderr, "[%s] 'count' param is NULL.\n", __FUNCTION__);
+ return NULL;
+ }
+
+ *count = 0;
+
+ if (!_utilx_check_key_symbol_list (KEYMAP_FILE))
+ return NULL;
+
+ names = calloc (symbol_list_len, sizeof (char*));
+ if (!names)
+ {
+ fprintf(stderr, "[%s] calloc failed.\n", __FUNCTION__);
+ return NULL;
+ }
+
+ *count = symbol_list_len;
+
+ i = 0;
+ entry = symbol_list;
+ while (entry && i < symbol_list_len)
+ {
+ names[i++] = entry->name;
+ entry = entry->next;
+ }
+
+ return (const char**)names;
+}
+
+API const char* utilx_get_key_symbol (const char *key_name)
+{
+ Symbol_Entry *entry;
+ XrmQuark quark;
+
+ if (!_utilx_check_key_symbol_list (KEYMAP_FILE))
+ return NULL;
+
+ quark = XrmStringToQuark (key_name);
+ entry = symbol_list;
+
+ while (entry)
+ {
+ if (entry->quark == quark)
+ return (const char*)entry->symbol;
+
+ entry = entry->next;
+ }
+
+ return NULL;
+}
+
API int utilx_grab_key (Display* disp, Window win, const char* key, int grab_mode)
{
unsigned long cnt;
return -1;
}
+ if( NULL == key )
+ {
+ fprintf(stderr, "[%s] key is NULL\n", __FUNCTION__);
+ return -1;
+ }
+
if (_atom_grab_key == None) {
_atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
}
return -1;
}
+ if( NULL == key )
+ {
+ fprintf(stderr, "[%s] key is NULL\n", __FUNCTION__);
+ return -1;
+ }
+
if (_atom_grab_key == None) {
_atom_grab_key = XInternAtom(disp, STR_ATOM_GRAB_KEY, False);
}