summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2007-10-22 12:26:53 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2007-10-22 12:26:53 +0000
commitfa13cbee8062d949d3cdcf17723183a5579493f2 (patch)
tree72df7c2b3eba20bf3011e22e067b7029a20b8868
parentba482642f2aeeeaa39fd22f68b908fc09b6f63ac (diff)
downloadrockbox-fa13cbee8062d949d3cdcf17723183a5579493f2.tar.gz
rockbox-fa13cbee8062d949d3cdcf17723183a5579493f2.zip
First go at getting the touchpad working in the ui. lists only for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15264 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/action.c56
-rw-r--r--apps/action.h10
-rw-r--r--apps/gui/list.c84
3 files changed, 149 insertions, 1 deletions
diff --git a/apps/action.c b/apps/action.c
index 5aeab25e1d..989313f41c 100644
--- a/apps/action.c
+++ b/apps/action.c
@@ -35,6 +35,10 @@ static intptr_t last_data = 0;
35static int last_action = ACTION_NONE; 35static int last_action = ACTION_NONE;
36static bool repeated = false; 36static bool repeated = false;
37 37
38#ifdef HAVE_TOUCHPAD
39static bool short_press = false;
40#endif
41
38#define REPEAT_WINDOW_TICKS HZ/10 42#define REPEAT_WINDOW_TICKS HZ/10
39static int last_action_tick = 0; 43static int last_action_tick = 0;
40 44
@@ -132,7 +136,25 @@ static int get_action_worker(int context, int timeout,
132 return ACTION_NONE; /* "safest" return value */ 136 return ACTION_NONE; /* "safest" return value */
133 } 137 }
134 last_context = context; 138 last_context = context;
135 139#ifdef HAVE_TOUCHPAD
140 if (button&BUTTON_TOUCHPAD)
141 {
142 repeated = false;
143 short_press = false;
144 if (last_button&BUTTON_TOUCHPAD)
145 {
146 if ((button&BUTTON_REL) &&
147 ((last_button&BUTTON_REPEAT)==0))
148 {
149 short_press = true;
150 }
151 else if (button&BUTTON_REPEAT)
152 repeated = true;
153 }
154 last_button = button;
155 return ACTION_TOUCHPAD;
156 }
157#endif
136#ifndef HAS_BUTTON_HOLD 158#ifndef HAS_BUTTON_HOLD
137 screen_has_lock = ((context&ALLOW_SOFTLOCK)==ALLOW_SOFTLOCK); 159 screen_has_lock = ((context&ALLOW_SOFTLOCK)==ALLOW_SOFTLOCK);
138 if (screen_has_lock && (keys_locked == true)) 160 if (screen_has_lock && (keys_locked == true))
@@ -250,3 +272,35 @@ int get_action_statuscode(int *button)
250 ret |= ACTION_REPEAT; 272 ret |= ACTION_REPEAT;
251 return ret; 273 return ret;
252} 274}
275
276#ifdef HAVE_TOUCHPAD
277/* return BUTTON_NONE on error
278 BUTTON_REPEAT if repeated press
279 BUTTON_REL if its a short press
280 BUTTON_TOUCHPAD otherwise
281*/
282int action_get_touchpad_press(short *x, short *y)
283{
284 static int last_data = 0;
285 int data;
286 if ((last_button&BUTTON_TOUCHPAD) == 0)
287 return BUTTON_NONE;
288 data = button_get_data();
289 if (last_button&BUTTON_REL)
290 {
291 *x = (last_data&0xffff0000)>>16;
292 *y = (last_data&0xffff);
293 }
294 else
295 {
296 *x = (data&0xffff0000)>>16;
297 *y = (data&0xffff);
298 }
299 last_data = data;
300 if (repeated)
301 return BUTTON_REPEAT;
302 if (short_press)
303 return BUTTON_REL;
304 return BUTTON_NONE;
305}
306#endif
diff --git a/apps/action.h b/apps/action.h
index 9859c2c50c..c1c60c9b0b 100644
--- a/apps/action.h
+++ b/apps/action.h
@@ -78,6 +78,7 @@ enum {
78 ACTION_NONE = BUTTON_NONE, 78 ACTION_NONE = BUTTON_NONE,
79 ACTION_UNKNOWN, 79 ACTION_UNKNOWN,
80 ACTION_REDRAW, /* returned if keys are locked and we splash()'ed */ 80 ACTION_REDRAW, /* returned if keys are locked and we splash()'ed */
81 ACTION_TOUCHPAD,
81 82
82 /* standard actions, use these first */ 83 /* standard actions, use these first */
83 ACTION_STD_PREV, 84 ACTION_STD_PREV,
@@ -259,4 +260,13 @@ int get_action_statuscode(int *button);
259 BUTTON_NONE or flagged with SYS_EVENT */ 260 BUTTON_NONE or flagged with SYS_EVENT */
260intptr_t get_action_data(void); 261intptr_t get_action_data(void);
261 262
263#ifdef HAVE_TOUCHPAD
264/* return BUTTON_NONE on error
265 BUTTON_REPEAT if repeated press
266 BUTTON_REL if its a short press
267 BUTTON_TOUCHPAD otherwise
268*/
269int action_get_touchpad_press(short *x, short *y);
270#endif
271
262#endif /* __ACTION_H__ */ 272#endif /* __ACTION_H__ */
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 2450720a13..feee1ec7a7 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -911,6 +911,81 @@ void gui_synclist_speak_item(struct gui_synclist * lists)
911 911
912extern intptr_t get_action_data(void); 912extern intptr_t get_action_data(void);
913 913
914#if defined(HAVE_TOUCHPAD)
915unsigned gui_synclist_do_touchpad(struct gui_synclist * lists)
916{
917 struct gui_list *gui_list = &(lists->gui_list[SCREEN_MAIN]);
918 short x,y;
919 unsigned button = action_get_touchpad_press(&x, &y);
920 int line;
921 if (x<SCROLLBAR_WIDTH)
922 {
923 /* top left corner is hopefully GO_TO_ROOT */
924 if (y<STATUSBAR_HEIGHT)
925 {
926 if (button == BUTTON_REL)
927 return ACTION_STD_MENU;
928 else if (button == BUTTON_REPEAT)
929 return ACTION_STD_CONTEXT;
930 else
931 return ACTION_NONE;
932 }
933 /* scroll bar */
934 else
935 {
936 int new_selection, nb_lines;
937 int height, size;
938 nb_lines = gui_list->display->nb_lines - SHOW_LIST_TITLE;
939 if (nb_lines < gui_list->nb_items)
940 {
941 height = nb_lines * gui_list->display->char_height;
942 size = height*nb_lines / gui_list->nb_items;
943 new_selection = (y*(gui_list->nb_items-nb_lines))/(height-size);
944 gui_synclist_select_item(lists, new_selection);
945 nb_lines /= 2;
946 if (new_selection - gui_list->start_item > nb_lines)
947 {
948 new_selection = gui_list->start_item+nb_lines;
949 }
950 FOR_NB_SCREENS(line)
951 lists->gui_list[line].selected_item = new_selection;
952 return ACTION_REDRAW;
953 }
954 }
955 }
956 else
957 {
958 if (button != BUTTON_REL && button != BUTTON_REPEAT)
959 return ACTION_NONE;
960 /* title or statusbar is cancel */
961 if (global_settings.statusbar)
962 {
963 if (y < STATUSBAR_HEIGHT && !SHOW_LIST_TITLE )
964 return ACTION_STD_CANCEL;
965 y -= STATUSBAR_HEIGHT;
966 }
967 /* title goes up one level */
968 if (SHOW_LIST_TITLE)
969 {
970 if (y < gui_list->display->char_height)
971 return ACTION_STD_CANCEL;
972 y -= gui_list->display->char_height;
973 }
974 /* pressing an item will select it.
975 pressing the selected item will "enter" it */
976 line = y / gui_list->display->char_height;
977 if (line != gui_list->selected_item - gui_list->start_item)
978 gui_synclist_select_item(lists, gui_list->start_item+line);
979
980 if (button == BUTTON_REPEAT)
981 return ACTION_STD_CONTEXT;
982 else
983 return ACTION_STD_OK;
984 }
985 return ACTION_NONE;
986}
987#endif
988
914bool gui_synclist_do_button(struct gui_synclist * lists, 989bool gui_synclist_do_button(struct gui_synclist * lists,
915 unsigned *actionptr, enum list_wrap wrap) 990 unsigned *actionptr, enum list_wrap wrap)
916{ 991{
@@ -950,6 +1025,11 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
950 } 1025 }
951 } 1026 }
952#endif 1027#endif
1028
1029#if defined(HAVE_TOUCHPAD)
1030 if (action == ACTION_TOUCHPAD)
1031 action = *actionptr = gui_synclist_do_touchpad(lists);
1032#endif
953 1033
954 switch (wrap) 1034 switch (wrap)
955 { 1035 {
@@ -971,6 +1051,10 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
971 1051
972 switch (action) 1052 switch (action)
973 { 1053 {
1054 case ACTION_REDRAW:
1055 gui_synclist_draw(lists);
1056 return true;
1057
974#ifdef HAVE_VOLUME_IN_LIST 1058#ifdef HAVE_VOLUME_IN_LIST
975 case ACTION_LIST_VOLUP: 1059 case ACTION_LIST_VOLUP:
976 global_settings.volume += 2; 1060 global_settings.volume += 2;