diff options
author | nags <nags@nags-desktop.(none)> | 2009-08-12 23:51:44 -0700 |
---|---|---|
committer | nags <nags@nags-desktop.(none)> | 2009-08-12 23:51:44 -0700 |
commit | b2c4af14c4fced765b39f1fcf19380dcb5442808 (patch) | |
tree | 0a7362c3be0a97ed5e3ec94fd55d3278fb68e69e | |
parent | db19a8e25b911effe78630ad016a3bf44fe0b117 (diff) |
2009-08-12 Nagappan Alagappan <nagappan@gmail.com>
* device.c (get_keyboard_keycodes): Fixes bug 590755, Keycodes
mismatch using generatekeyevent from python-ldtp.
-rw-r--r-- | src/ChangeLog | 5 | ||||
-rw-r--r-- | src/device.c | 93 | ||||
-rw-r--r-- | src/device.h | 4 | ||||
-rw-r--r-- | src/ldtp.c | 27 | ||||
-rw-r--r-- | src/link.c | 3 |
5 files changed, 103 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 8b63262..a64f22f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-08-12 Nagappan Alagappan <nagappan@gmail.com> + + * device.c (get_keyboard_keycodes): Fixes bug 590755, Keycodes + mismatch using generatekeyevent from python-ldtp. + 2009-08-11 Nagappan Alagappan <nagappan@gmail.com> * ldtp.c (get_current_time): Fixes bug 587614, Method to measure how diff --git a/src/device.c b/src/device.c index 54ae713..9aa5485 100644 --- a/src/device.c +++ b/src/device.c @@ -31,6 +31,8 @@ #include "ldtp-gui-comp.h" #include "device.h" +struct NonPrint_Key_Synth NonPrint_Key_Synth_Vals[300]; + static LDTPErrorCode mouse_left_click (Accessible *object, FILE *log_fp) { @@ -158,26 +160,7 @@ get_key_value (gchar *keyval) {'{', 34}, {'}', 35}, {':', 47}, {'\"',48}, {'~', 49}, {'|', 51}, {'<', 59}, {'>', 60}, {'\?', 61}}; - /* - PrtScrn: http://gentoo-wiki.com/TIP_Make_a_Screenshot_with_PrintScreen_Key - xmodmap -pke | grep -i print - */ - static struct NonPrint_Key_Synth NonPrint_Key_Synth_Vals[] = {{"escape", 9}, {"esc", 9}, {"backspace", 22}, - {"bksp", 22}, {"ctrl", 37}, {"windowskey", 115}, - {"tab", 23}, {"return", 36}, {"enter", 36}, - {"shift", 50}, {"shiftl", 50}, {"shiftr", 62}, - {"home", 97}, {"end", 103}, {"window", 115}, - {"alt", 64}, {"altl", 64}, {"altr", 113}, - {"up", 98}, {"down", 104}, {"right", 102}, - {"left", 100}, {"space", 65}, {"capslock", 66}, - {"caps", 66}, {"menu", 117}, {"ins", 106}, - {"del", 107}, {"insert", 106}, {"delete", 107}, - {"pageup", 99}, {"pagedown", 105}, {"pgup", 99}, - {"pgdown", 105}, {"numlock", 77}, {"scrolllock", 78}, - {"F1", 67}, {"F2", 68}, {"F3", 69}, {"F4", 70}, - {"F5", 71}, {"F6", 72}, {"F7", 73}, {"F8", 74}, - {"F9", 75}, {"F10", 76}, {"F11", 95}, {"F12", 96}, - {"prtscrn", 111}, {NULL, 0}}; + struct KeyValue return_val; /* will contain the return values */ gint index; @@ -459,3 +442,73 @@ device_main (LDTPClientContext* cctxt, int command) } return error; } + +void +get_keyboard_keycodes() { + FILE *fd; + size_t readed; + char *src; + //char *keycode_symbol_start; + int keycode; + gchar **lines; + gchar *line; + int i; + int index = 0; + + struct NonPrint_Key_Synth old_NonPrint_Key_Synth_Vals[] = {{"escape", 9}, {"esc", 9}, {"backspace", 22}, + {"bksp", 22}, {"ctrl", 37}, {"windowskey", 115}, + {"tab", 23}, {"return", 36}, {"enter", 36}, + {"shift", 50}, {"shiftl", 50}, {"shiftr", 62}, + {"home", 97}, {"end", 103}, {"window", 115}, + {"alt", 64}, {"altl", 64}, {"altr", 113}, + {"up", 98}, {"down", 104}, {"right", 102}, + {"left", 100}, {"space", 65}, {"capslock", 66}, + {"caps", 66}, {"menu", 117}, {"ins", 106}, + {"del", 107}, {"insert", 106}, {"delete", 107}, + {"pageup", 99}, {"pagedown", 105}, {"pgup", 99}, + {"pgdown", 105}, {"numlock", 77}, {"scrolllock", 78}, + {"F1", 67}, {"F2", 68}, {"F3", 69}, {"F4", 70}, + {"F5", 71}, {"F6", 72}, {"F7", 73}, {"F8", 74}, + {"F9", 75}, {"F10", 76}, {"F11", 95}, {"F12", 96}, + {"prtscrn", 111}}; + + + src = (char *) malloc(sizeof(char) * 100); + readed = 0; + + fd = popen("xmodmap -pke", "r"); + + while ( ! feof(fd)) { + readed += fread(src + readed, 1, 100, fd); + src = (char *) realloc(src, sizeof(char)*(readed+100)); + } + + pclose(fd); + + lines = g_strsplit(src, "\n", 0); + + for (index=0; lines != NULL && strcmp(*lines, ""); lines++) { + gchar **split; + line = *lines; + + split = g_strsplit(line, "=", 2); + keycode = atoi(split[0] + 7); + + if (strlen(split[1]) > 0) { + gchar **space_split = g_strsplit(split[1], " ", 3); + NonPrint_Key_Synth_Vals[index].sym = space_split[1]; + NonPrint_Key_Synth_Vals[index].KeyVal = keycode; + index++; + } + } + + int old_len = sizeof(old_NonPrint_Key_Synth_Vals) / sizeof(struct NonPrint_Key_Synth); + + for(i=0 ; index < 300 && i < old_len; index++, i++) + NonPrint_Key_Synth_Vals[index] = old_NonPrint_Key_Synth_Vals[i]; + + NonPrint_Key_Synth_Vals[index].sym = NULL; + NonPrint_Key_Synth_Vals[index].KeyVal = 0; + + return; +} diff --git a/src/device.h b/src/device.h index 761320a..0baf341 100644 --- a/src/device.h +++ b/src/device.h @@ -50,5 +50,7 @@ struct KeyValue { gboolean non_print_key; gint value; }; - + +void get_keyboard_keycodes(); + #endif @@ -34,6 +34,7 @@ #include "client-handler.h" #include "ldtp-error.h" #include "ldtp-logger.h" +#include "device.h" #ifndef ENABLE_GOPTIONPARSE #include <getopt.h> @@ -75,11 +76,16 @@ static GOptionEntry entries [] = #endif static LDTPClientContext* -is_window_reg_for_events (char *context) +is_window_reg_for_events (char *context, char *window_name) { LDTPClientContext *cctxt = NULL; if (event_notifier) { cctxt = g_hash_table_find (event_notifier, search_title_based, context); + if (cctxt && context && cctxt->req && cctxt->req->context) { + g_print ("Registered window title: %s - %s\n", context, cctxt->req->context); + return cctxt; + } + cctxt = g_hash_table_find (event_notifier, search_title_based, window_name); if (cctxt && context && cctxt->req && cctxt->req->context) g_print ("Registered window title: %s - %s\n", context, cctxt->req->context); } @@ -144,7 +150,6 @@ report_window_event (const AccessibleEvent *event, void *user_data) } else window_name = get_window_name_in_appmap_format (title, Accessible_getRole (event->source)); - SPI_freeString (title); if (window_name) { char *current_time = get_current_time (); if (current_time) { @@ -165,23 +170,27 @@ report_window_event (const AccessibleEvent *event, void *user_data) g_strdup (window_name), start_time); } - } else + } else { + SPI_freeString (title); return; - if ((cctxt = is_window_reg_for_events (window_name))) { + } + if ((cctxt = is_window_reg_for_events (window_name, title))) { /* Notify to client */ if (!cctxt || !cctxt->resp) { g_print ("CCTXT is lost\n"); g_free (window_name); + SPI_freeString (title); return; } - cctxt->resp->data = g_strdup (title); - cctxt->resp->data_len = g_utf8_strlen (title, -1); + cctxt->resp->data = g_strdup (window_name); + cctxt->resp->data_len = g_utf8_strlen (window_name, -1); cctxt->resp->resp_status = LDTP_ERROR_SUCCESS; generate_notification_packet (cctxt, &status, &resp_pckt, &resp_size); if (status != LDTP_ERROR_SUCCESS) { + SPI_freeString (title); g_free (window_name); g_print ("Error generating notification\n"); return; @@ -191,10 +200,12 @@ report_window_event (const AccessibleEvent *event, void *user_data) send_response (cctxt->sock_fd, resp_pckt, resp_size, &status); g_free (cctxt->resp->data); cctxt->resp->data = NULL; + SPI_freeString (title); g_free (window_name); return; } g_free (window_name); + SPI_freeString (title); } else if (g_ascii_strcasecmp ("window:close", event->type) == 0 || g_ascii_strcasecmp ("window:deactivate", event->type) == 0 || g_ascii_strcasecmp ("window:destroy", event->type) == 0) { @@ -682,6 +693,10 @@ main (int argc, char **argv) } debug_log_file_name = get_log_file_name (); ldtp_debug_log_fp = fopen (debug_log_file_name, "a"); + + /* get the keyboard keycodes from xmodmod -pke */ + get_keyboard_keycodes(); + spi_init = SPI_init (); window_listener = SPI_createAccessibleEventListener (report_window_event, NULL); @@ -33,7 +33,6 @@ static LDTPErrorCode click (Accessible *object, FILE *log_fp) { - LDTPErrorCode error; SPIBoolean flag = FALSE; AccessibleAction *action; @@ -61,7 +60,7 @@ click (Accessible *object, FILE *log_fp) } LDTPErrorCode -link_main (LDTPClientContext* cctxt, int command) +link_main (LDTPClientContext *cctxt, int command) { LDTPErrorCode error; switch (command) { |