static void handle(void) { static long old_mx, old_my, old_mb; static long update_needed = 0; static EVENT event; WIDGET *new_mfocus = NULL; old_mx = curr_mx; old_my = curr_my; old_mb = curr_mb; while (input->get_event(&event)) { switch (event.type) { case EV_REL: if (event.code == REL_X) set_pos(curr_mx + event.value, curr_my); else if (event.code == REL_Y) set_pos(curr_mx, curr_my + event.value); break; case EV_ABS: if (event.code == ABS_X) set_pos(event.value, curr_my); else if (event.code == ABS_Y) set_pos(curr_mx, event.value); break; case EV_KEY: if (event.value == 1) { press_cnt++; if (event.code == BTN_LEFT) curr_mb = curr_mb | 0x01; if (event.code == BTN_RIGHT) curr_mb = curr_mb | 0x02; keytab[event.code] = 1; if (get_ascii(event.code) || (event.code >= KEY_UP && event.code <= KEY_DELETE)) { curr_keystate = USERSTATE_KEY_PRESS; curr_keycode = event.code; tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode); } else { curr_keystate = USERSTATE_KEY_IDLE; curr_keycode = 0; } } else if (event.value == 0) { press_cnt--; if (event.code == BTN_LEFT) curr_mb = curr_mb & 0x00fe; if (event.code == BTN_RIGHT) curr_mb = curr_mb & 0x00fd; keytab[event.code] = 0; curr_keystate = USERSTATE_KEY_IDLE; curr_keycode = 0; } break; } update_mfocus(); if (event.type == EV_KEY) { WIDGET *win_kfocus = NULL; /* make clicked window the active one */ if (curr_mfocus && key_sets_focus(event.code)) { WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus); set_active_window(w, 1); } if (curr_window) { win_kfocus = curr_window->win->get_kfocus(curr_window); /* redefine keyboard focus */ if (curr_mfocus && key_sets_focus(event.code) && curr_mfocus != win_kfocus) curr_mfocus->gen->focus(curr_mfocus); /* request new keyboard focus - just in case it denied the focus */ win_kfocus = curr_window->win->get_kfocus(curr_window); } if ((event.value == 1) && (press_cnt == 1)) { WIDGET *old_receiver = curr_receiver; /* send keyboard event to actually focused widget if set */ if (win_kfocus && !key_sets_focus(event.code)) { if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus); curr_receiver = win_kfocus; } else { if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus); curr_receiver = curr_mfocus; } if (old_receiver) old_receiver->gen->dec_ref(old_receiver); } if (curr_receiver) curr_receiver->gen->handle_event(curr_receiver, &event, NULL); } } /* * Hell! We got more key release events than press events * This can happen when a key is pressed during the bootup */ if (press_cnt < 0) press_cnt = 0; tick->handle(); switch (curr_state) { case USERSTATE_IDLE: /* if mouse position changed -> deliver motion event */ if (old_mx != curr_mx && curr_mfocus) { event.type = EV_ABS; event.code = ABS_X; event.value = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus); curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL); } if (old_my != curr_my && curr_mfocus) { event.type = EV_ABS; event.code = ABS_Y; event.value = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus); curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL); } break; case USERSTATE_TOUCH: if (curr_tick_callback) curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); if (press_cnt == 0) idle(); new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my); if (new_mfocus != curr_mfocus) { if (new_mfocus == curr_selected) { curr_selected->gen->set_state(curr_selected,1); curr_selected->gen->update(curr_selected); } else { curr_selected->gen->set_state(curr_selected,0); curr_selected->gen->update(curr_selected); } if (curr_mfocus) curr_mfocus->gen->dec_ref(curr_mfocus); curr_mfocus = new_mfocus; if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus); } break; case USERSTATE_DRAG: if (press_cnt == 0) idle(); if (curr_tick_callback) { curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); } if (old_mx != curr_mx || old_my != curr_my || update_needed) { update_needed = 1; if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr)) { update_needed = 0; curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy); } } break; case USERSTATE_GRAB: #if 0 /* if mouse position changed -> deliver motion event */ if (old_mx != curr_mx || old_my != curr_my) { s32 min_x = curr_selected->gen->get_abs_x(curr_selected); s32 min_y = curr_selected->gen->get_abs_y(curr_selected); s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1; s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1; if (curr_mx < min_x || curr_my < min_y || curr_mx > max_x || curr_my > max_y) { if (curr_mx < min_x) curr_mx = min_x; if (curr_my < min_y) curr_my = min_y; if (curr_mx > max_x) curr_mx = max_x; if (curr_my > max_y) curr_my = max_y; set_pos(curr_mx, curr_my); } event.type = EVENT_MOTION; event.abs_x = curr_mx - min_x; event.abs_y = curr_my - min_y; event.rel_x = curr_mx - old_mx; event.rel_y = curr_my - old_my; curr_selected->gen->handle_event(curr_selected, &event, NULL); } if (curr_tick_callback) { curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); } #endif break; } scrdrv->set_mouse_pos(curr_mx, curr_my); }
static void handle(EVENT *e, int count) { int old_mx, old_my, old_mb; int i; static int update_needed = 0; EVENT event; WIDGET *new_mfocus = NULL; old_mx = curr_mx; old_my = curr_my; old_mb = curr_mb; for(i=0;i<count;i++) { switch (e[i].type) { case EVENT_MOTION: set_pos(curr_mx + e[i].rel_x, curr_my + e[i].rel_y); break; case EVENT_ABSMOTION: set_pos(e[i].abs_x, e[i].abs_y); break; case EVENT_PRESS: press_cnt++; if (e[i].code == MTK_BTN_LEFT) curr_mb = curr_mb | 0x01; if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb | 0x02; keytab[e[i].code] = 1; if (get_ascii(e[i].code) || (e[i].code >= MTK_KEY_UP && e[i].code <= MTK_KEY_DELETE)) { curr_keystate = USERSTATE_KEY_PRESS; curr_keycode = e[i].code; tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode); } else { curr_keystate = USERSTATE_KEY_IDLE; curr_keycode = 0; } break; case EVENT_RELEASE: press_cnt--; if ((curr_state == USERSTATE_DRAG) && curr_motion_callback) curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy); if (e[i].code == MTK_BTN_LEFT) curr_mb = curr_mb & 0x00fe; if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb & 0x00fd; keytab[e[i].code] = 0; curr_keystate = USERSTATE_KEY_IDLE; curr_keycode = 0; break; } update_mfocus(); if ((e[i].type == EVENT_PRESS) || (e[i].type == EVENT_RELEASE)) { WIDGET *win_kfocus = NULL; /* make clicked window the active one */ if (curr_mfocus && key_sets_focus(e[i].code)) { WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus); /* ignore clicks on the desktop (last window of window stack) */ if (w->gen->get_next((WIDGET *)w)) set_active_window(w, 1); } if (curr_window) { win_kfocus = curr_window->win->get_kfocus(curr_window); /* redefine keyboard focus */ if (curr_mfocus && key_sets_focus(e[i].code) && curr_mfocus != win_kfocus) curr_mfocus->gen->focus(curr_mfocus); /* request new keyboard focus - just in case it denied the focus */ win_kfocus = curr_window->win->get_kfocus(curr_window); } if ((e[i].type == EVENT_PRESS) && (press_cnt == 1)) { WIDGET *old_receiver = curr_receiver; /* send keyboard event to actually focused widget if set */ if (win_kfocus && !key_sets_focus(e[i].code)) { if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus); curr_receiver = win_kfocus; } else { if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus); curr_receiver = curr_mfocus; } if (old_receiver) old_receiver->gen->dec_ref(old_receiver); } if (curr_receiver) curr_receiver->gen->handle_event(curr_receiver, &e[i], NULL); } } /* * Hell! We got more key release events than press events * This can happen when a key is pressed during the bootup */ if (press_cnt < 0) press_cnt = 0; tick->handle(); switch (curr_state) { case USERSTATE_IDLE: /* if mouse position changed -> deliver motion event */ if (old_mx != curr_mx || old_my != curr_my) { if (curr_mfocus) { event.type = EVENT_MOTION; event.abs_x = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus); event.abs_y = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus); event.rel_x = curr_mx - old_mx; event.rel_y = curr_my - old_my; curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL); } } break; case USERSTATE_TOUCH: if (!curr_selected) break; if (curr_tick_callback) curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); if (press_cnt == 0) idle(); new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my); if (new_mfocus != curr_mfocus) { if (new_mfocus == curr_selected) { if (curr_selected) { curr_selected->gen->set_state(curr_selected,1); curr_selected->gen->update(curr_selected); } } else { if (curr_selected) { curr_selected->gen->set_state(curr_selected,0); curr_selected->gen->update(curr_selected); } } if (curr_mfocus) curr_mfocus->gen->dec_ref(curr_mfocus); curr_mfocus = new_mfocus; if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus); } break; case USERSTATE_DRAG: if (press_cnt == 0) idle(); if (curr_tick_callback) { curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); } if (old_mx != curr_mx || old_my != curr_my || update_needed) { update_needed = 1; if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr)) { update_needed = 0; curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy); } } break; case USERSTATE_GRAB: /* if mouse position changed -> deliver motion event */ if (old_mx != curr_mx || old_my != curr_my) { s32 min_x = curr_selected->gen->get_abs_x(curr_selected); s32 min_y = curr_selected->gen->get_abs_y(curr_selected); s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1; s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1; if (curr_mx < min_x || curr_my < min_y || curr_mx > max_x || curr_my > max_y) { if (curr_mx < min_x) curr_mx = min_x; if (curr_my < min_y) curr_my = min_y; if (curr_mx > max_x) curr_mx = max_x; if (curr_my > max_y) curr_my = max_y; set_pos(curr_mx, curr_my); } event.type = EVENT_MOTION; event.abs_x = curr_mx - min_x; event.abs_y = curr_my - min_y; event.rel_x = curr_mx - old_mx; event.rel_y = curr_my - old_my; curr_selected->gen->handle_event(curr_selected, &event, NULL); } if (curr_tick_callback) { curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy); } break; } scrdrv->set_mouse_pos(curr_mx, curr_my); }