Changeset 111d2d6 in mainline
- Timestamp:
- 2012-08-17T17:05:06Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 01e397ac
- Parents:
- ad78054
- Location:
- uspace
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
rad78054 r111d2d6 95 95 generic/inetping.c \ 96 96 generic/io/asprintf.c \ 97 generic/io/input.c \ 97 98 generic/io/io.c \ 98 99 generic/io/chargrid.c \ -
uspace/lib/c/include/io/console.h
rad78054 r111d2d6 37 37 38 38 #include <sys/time.h> 39 #include <io/kbd_event.h> 39 40 #include <io/keycode.h> 40 41 #include <async.h> … … 70 71 } console_ctrl_t; 71 72 72 typedef enum {73 KEY_PRESS,74 KEY_RELEASE75 } kbd_event_type_t;76 77 /** Console event structure. */78 typedef struct {79 /** List handle */80 link_t link;81 82 /** Press or release event. */83 kbd_event_type_t type;84 85 /** Keycode of the key that was pressed or released. */86 keycode_t key;87 88 /** Bitmask of modifiers held. */89 keymod_t mods;90 91 /** The character that was generated or '\0' for none. */92 wchar_t c;93 } kbd_event_t;94 95 73 extern console_ctrl_t *console_init(FILE *, FILE *); 96 74 extern void console_done(console_ctrl_t *); -
uspace/srv/hid/compositor/compositor.c
rad78054 r111d2d6 49 49 #include <adt/prodcons.h> 50 50 #include <adt/list.h> 51 #include <io/input.h> 51 52 #include <ipc/graph.h> 52 #include <ipc/input.h>53 53 #include <ipc/window.h> 54 54 … … 143 143 static LIST_INITIALIZE(viewport_list); 144 144 145 static async_sess_t *input_sess; 145 /** Input server proxy */ 146 static input_t *input; 147 148 static int comp_key_press(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t); 149 static int comp_mouse_move(input_t *, int, int); 150 static int comp_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned); 151 static int comp_mouse_button(input_t *, int, int); 152 153 static input_ev_ops_t input_ev_ops = { 154 .key = comp_key_press, 155 .move = comp_mouse_move, 156 .abs_move = comp_abs_move, 157 .button = comp_mouse_button 158 }; 159 160 static void input_disconnect(void); 161 162 163 static pointer_t *input_pointer(input_t *input) 164 { 165 return input->user; 166 } 146 167 147 168 static pointer_t *pointer_create() … … 759 780 fibril_mutex_unlock(&viewport_list_mtx); 760 781 loc_service_unregister(winreg_id); 761 async_hangup(input_sess);782 input_disconnect(); 762 783 763 784 /* Close all clients and their windows. */ … … 1055 1076 } 1056 1077 1057 static void comp_mouse_move(pointer_t *pointer, ipc_callid_t iid, ipc_call_t *icall) 1058 { 1059 int dx = (int) IPC_GET_ARG1(*icall); 1060 int dy = (int) IPC_GET_ARG2(*icall); 1078 static int comp_abs_move(input_t *input, unsigned x , unsigned y, 1079 unsigned max_x, unsigned max_y) 1080 { 1081 /* XXX TODO */ 1082 return EOK; 1083 } 1084 1085 static int comp_mouse_move(input_t *input, int dx, int dy) 1086 { 1087 pointer_t *pointer = input_pointer(input); 1061 1088 1062 1089 /* Update pointer position. */ … … 1118 1145 } 1119 1146 1120 async_answer_0(iid, EOK); 1121 } 1122 1123 static void comp_mouse_button(pointer_t *pointer, ipc_callid_t iid, ipc_call_t *icall) 1124 { 1125 sysarg_t btn_num = IPC_GET_ARG1(*icall); 1126 bool pressed = (bool) IPC_GET_ARG2(*icall); 1127 1128 if (pressed) { 1147 return EOK; 1148 } 1149 1150 static int comp_mouse_button(input_t *input, int bnum, int bpress) 1151 { 1152 pointer_t *pointer = input_pointer(input); 1153 1154 if (bpress) { 1129 1155 pointer->btn_hpos = pointer->hpos; 1130 1156 pointer->btn_vpos = pointer->vpos; 1131 pointer->btn_num = b tn_num;1157 pointer->btn_num = bnum; 1132 1158 pointer->pressed = true; 1133 1159 … … 1137 1163 if (!win || !win->surface) { 1138 1164 fibril_mutex_unlock(&window_list_mtx); 1139 async_answer_0(iid, EOK); 1140 return; 1165 return EOK; 1141 1166 } 1142 1167 sysarg_t x, y, width, height; … … 1154 1179 event->data.pos.pos_id = pointer->id; 1155 1180 event->data.pos.type = POS_PRESS; 1156 event->data.pos.btn_num = b tn_num;1181 event->data.pos.btn_num = bnum; 1157 1182 event->data.pos.hpos = x; 1158 1183 event->data.pos.vpos = y; 1159 1184 comp_post_event(event); 1160 1185 } else { 1161 async_answer_0(iid, ENOMEM); 1162 return; 1163 } 1164 } 1165 } else if (pointer->pressed && pointer->btn_num == btn_num) { 1186 return ENOMEM; 1187 } 1188 } 1189 } else if (pointer->pressed && pointer->btn_num == (unsigned)bnum) { 1166 1190 pointer->pressed = false; 1167 1191 … … 1191 1215 pointer->grab_flags = GF_EMPTY; 1192 1216 fibril_mutex_unlock(&window_list_mtx); 1193 async_answer_0(iid, EOK); 1194 return; 1217 return EOK; 1195 1218 } 1196 1219 … … 1257 1280 event->data.pos.pos_id = pointer->id; 1258 1281 event->data.pos.type = POS_RELEASE; 1259 event->data.pos.btn_num = b tn_num;1282 event->data.pos.btn_num = bnum; 1260 1283 event->data.pos.hpos = point_x; 1261 1284 event->data.pos.vpos = point_y; … … 1263 1286 pointer->grab_flags = GF_EMPTY; 1264 1287 1265 } else if (within_client && (pointer->grab_flags == GF_EMPTY) && (b tn_num == 1)) {1288 } else if (within_client && (pointer->grab_flags == GF_EMPTY) && (bnum == 1)) { 1266 1289 1267 1290 /* Bring the window to the foreground. */ … … 1286 1309 } 1287 1310 1288 async_answer_0(iid, EOK); 1289 } 1290 1291 static void comp_key_press(ipc_callid_t iid, ipc_call_t *icall) 1292 { 1293 kbd_event_type_t type = IPC_GET_ARG1(*icall); 1294 keycode_t key = IPC_GET_ARG2(*icall); 1295 keymod_t mods = IPC_GET_ARG3(*icall); 1296 wchar_t c = IPC_GET_ARG4(*icall); 1297 1311 return EOK; 1312 } 1313 1314 static int comp_key_press(input_t *input, kbd_event_type_t type, keycode_t key, 1315 keymod_t mods, wchar_t c) 1316 { 1298 1317 bool win_transform = (mods & KM_ALT) && ( 1299 1318 key == KC_W || key == KC_S || key == KC_A || key == KC_D || … … 1378 1397 if (event == NULL) { 1379 1398 fibril_mutex_unlock(&window_list_mtx); 1380 async_answer_0(iid, ENOMEM); 1381 return; 1399 return ENOMEM; 1382 1400 } 1383 1401 … … 1448 1466 } else if (win_close) { 1449 1467 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); 1450 if (event == NULL) { 1451 async_answer_0(iid, ENOMEM); 1452 return; 1453 } 1468 if (event == NULL) 1469 return ENOMEM; 1454 1470 1455 1471 link_initialize(&event->link); … … 1594 1610 } else { 1595 1611 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); 1596 if (event == NULL) { 1597 async_answer_0(iid, ENOMEM); 1598 return; 1599 } 1612 if (event == NULL) 1613 return ENOMEM; 1600 1614 1601 1615 link_initialize(&event->link); … … 1609 1623 } 1610 1624 1611 async_answer_0(iid, EOK); 1612 } 1613 1614 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 1615 { 1625 return EOK; 1626 } 1627 1628 static int input_connect(const char *svc) 1629 { 1630 async_sess_t *sess; 1631 service_id_t dsid; 1632 1633 int rc = loc_service_get_id(svc, &dsid, 0); 1634 if (rc != EOK) { 1635 printf("%s: Input service %s not found\n", NAME, svc); 1636 return rc; 1637 } 1638 1639 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 1640 if (sess == NULL) { 1641 printf("%s: Unable to connect to input service %s\n", NAME, 1642 svc); 1643 return EIO; 1644 } 1645 1616 1646 fibril_mutex_lock(&pointer_list_mtx); 1617 1647 pointer_t *pointer = pointer_create(); … … 1622 1652 fibril_mutex_unlock(&pointer_list_mtx); 1623 1653 1624 /* Ignore parameters, the connection is already opened. */ 1625 while (true) { 1626 ipc_call_t call; 1627 ipc_callid_t callid = async_get_call(&call); 1628 1629 if (!IPC_GET_IMETHOD(call)) { 1630 fibril_mutex_lock(&pointer_list_mtx); 1631 if (pointer != NULL) { 1632 list_remove(&pointer->link); 1633 pointer_destroy(pointer); 1634 } 1635 fibril_mutex_unlock(&pointer_list_mtx); 1636 async_hangup(input_sess); 1637 return; 1638 } 1639 1640 switch (IPC_GET_IMETHOD(call)) { 1641 case INPUT_EVENT_KEY: 1642 comp_key_press(callid, &call); 1643 break; 1644 case INPUT_EVENT_MOVE: 1645 comp_mouse_move(pointer, callid, &call); 1646 break; 1647 case INPUT_EVENT_BUTTON: 1648 comp_mouse_button(pointer, callid, &call); 1649 break; 1650 default: 1651 async_answer_0(callid, EINVAL); 1652 } 1653 } 1654 } 1655 1656 static async_sess_t *input_connect(const char *svc) 1657 { 1658 async_sess_t *sess; 1659 service_id_t dsid; 1660 1661 int rc = loc_service_get_id(svc, &dsid, 0); 1662 if (rc == EOK) { 1663 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 1664 if (sess == NULL) { 1665 printf("%s: Unable to connect to input service %s\n", NAME, svc); 1666 return NULL; 1667 } 1668 } else 1669 return NULL; 1670 1671 async_exch_t *exch = async_exchange_begin(sess); 1672 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 1673 async_exchange_end(exch); 1674 1654 if (pointer == NULL) { 1655 printf("%s: Cannot create pointer.\n", NAME); 1656 async_hangup(sess); 1657 return ENOMEM; 1658 } 1659 1660 rc = input_open(sess, &input_ev_ops, pointer, &input); 1675 1661 if (rc != EOK) { 1676 1662 async_hangup(sess); 1677 printf("%s: Unable to c reate callback connection toservice %s (%s)\n",1663 printf("%s: Unable to communicate with service %s (%s)\n", 1678 1664 NAME, svc, str_error(rc)); 1679 return NULL; 1680 } 1681 1682 return sess; 1665 return rc; 1666 } 1667 1668 return EOK; 1669 } 1670 1671 static void input_disconnect(void) 1672 { 1673 pointer_t *pointer = input->user; 1674 input_close(input); 1675 pointer_destroy(pointer); 1683 1676 } 1684 1677 … … 1733 1726 1734 1727 /* Establish input bidirectional connection. */ 1735 input_sess = input_connect(input_svc); 1736 if (input_sess == NULL) { 1737 return -1; 1738 } 1728 rc = input_connect(input_svc); 1729 if (rc != EOK) 1730 return rc; 1739 1731 1740 1732 /* Create viewports and connect them to visualizers. */ … … 1742 1734 rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING); 1743 1735 if (rc != EOK) { 1744 async_hangup(input_sess);1736 input_disconnect(); 1745 1737 return -1; 1746 1738 } … … 1750 1742 rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt); 1751 1743 if (rc != EOK || svcs_cnt == 0) { 1752 async_hangup(input_sess);1744 input_disconnect(); 1753 1745 return -1; 1754 1746 } … … 1766 1758 1767 1759 if (list_empty(&viewport_list)) { 1768 async_hangup(input_sess);1760 input_disconnect(); 1769 1761 return -1; 1770 1762 } -
uspace/srv/hid/console/console.c
rad78054 r111d2d6 36 36 #include <stdio.h> 37 37 #include <adt/prodcons.h> 38 #include <i pc/input.h>38 #include <io/input.h> 39 39 #include <ipc/console.h> 40 40 #include <ipc/vfs.h> … … 43 43 #include <loc.h> 44 44 #include <event.h> 45 #include <io/kbd_event.h> 45 46 #include <io/keycode.h> 46 47 #include <io/chargrid.h> … … 81 82 } console_t; 82 83 83 /** Session to the input server*/84 static async_sess_t *input_sess;84 /** Input server proxy */ 85 static input_t *input; 85 86 86 87 /** Session to the output server */ … … 100 101 static console_t *active_console = &consoles[0]; 101 102 static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; 103 104 static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t); 105 static int input_ev_move(input_t *, int, int); 106 static int input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned); 107 static int input_ev_button(input_t *, int, int); 108 109 static input_ev_ops_t input_ev_ops = { 110 .key = input_ev_key, 111 .move = input_ev_move, 112 .abs_move = input_ev_abs_move, 113 .button = input_ev_button 114 }; 102 115 103 116 static void cons_update(console_t *cons) … … 195 208 } 196 209 197 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 198 { 199 /* Ignore parameters, the connection is already opened */ 200 while (true) { 201 ipc_call_t call; 202 ipc_callid_t callid = async_get_call(&call); 203 204 if (!IPC_GET_IMETHOD(call)) { 205 /* TODO: Handle hangup */ 206 async_hangup(input_sess); 207 return; 208 } 209 210 kbd_event_type_t type; 211 keycode_t key; 212 keymod_t mods; 213 wchar_t c; 214 215 switch (IPC_GET_IMETHOD(call)) { 216 case INPUT_EVENT_KEY: 217 type = IPC_GET_ARG1(call); 218 key = IPC_GET_ARG2(call); 219 mods = IPC_GET_ARG3(call); 220 c = IPC_GET_ARG4(call); 221 222 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 223 ((mods & KM_CTRL) == 0)) 224 cons_switch(&consoles[key - KC_F1]); 225 else { 226 /* Got key press/release event */ 227 kbd_event_t *event = 228 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 229 if (event == NULL) { 230 async_answer_0(callid, ENOMEM); 231 break; 232 } 233 234 link_initialize(&event->link); 235 event->type = type; 236 event->key = key; 237 event->mods = mods; 238 event->c = c; 239 240 /* 241 * Kernel console does not read events 242 * from us, so we will redirect them 243 * to the (last) active userspace console 244 * if necessary. 245 */ 246 console_t *target_console = cons_get_active_uspace(); 247 248 prodcons_produce(&target_console->input_pc, 249 &event->link); 250 } 251 252 async_answer_0(callid, EOK); 253 break; 254 case INPUT_EVENT_MOVE: 255 async_answer_0(callid, EOK); 256 break; 257 case INPUT_EVENT_BUTTON: 258 async_answer_0(callid, EOK); 259 break; 260 default: 261 async_answer_0(callid, EINVAL); 262 } 263 } 210 static int input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key, 211 keymod_t mods, wchar_t c) 212 { 213 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 214 ((mods & KM_CTRL) == 0)) { 215 cons_switch(&consoles[key - KC_F1]); 216 } else { 217 /* Got key press/release event */ 218 kbd_event_t *event = 219 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 220 if (event == NULL) { 221 return ENOMEM; 222 } 223 224 link_initialize(&event->link); 225 event->type = type; 226 event->key = key; 227 event->mods = mods; 228 event->c = c; 229 230 /* 231 * Kernel console does not read events 232 * from us, so we will redirect them 233 * to the (last) active userspace console 234 * if necessary. 235 */ 236 console_t *target_console = cons_get_active_uspace(); 237 238 prodcons_produce(&target_console->input_pc, 239 &event->link); 240 } 241 242 return EOK; 243 } 244 245 static int input_ev_move(input_t *input, int dx, int dy) 246 { 247 return EOK; 248 } 249 250 static int input_ev_abs_move(input_t *input, unsigned x , unsigned y, 251 unsigned max_x, unsigned max_y) 252 { 253 return EOK; 254 } 255 256 static int input_ev_button(input_t *input, int bnum, int bpress) 257 { 258 return EOK; 264 259 } 265 260 … … 518 513 } 519 514 520 static async_sess_t *input_connect(const char *svc)515 static int input_connect(const char *svc) 521 516 { 522 517 async_sess_t *sess; … … 524 519 525 520 int rc = loc_service_get_id(svc, &dsid, 0); 526 if (rc == EOK) { 527 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 528 if (sess == NULL) { 529 printf("%s: Unable to connect to input service %s\n", NAME, 530 svc); 531 return NULL; 532 } 533 } else 534 return NULL; 535 536 async_exch_t *exch = async_exchange_begin(sess); 537 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 538 async_exchange_end(exch); 539 521 if (rc != EOK) { 522 printf("%s: Input service %s not found\n", NAME, svc); 523 return rc; 524 } 525 526 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 527 if (sess == NULL) { 528 printf("%s: Unable to connect to input service %s\n", NAME, 529 svc); 530 return EIO; 531 } 532 533 rc = input_open(sess, &input_ev_ops, NULL, &input); 540 534 if (rc != EOK) { 541 535 async_hangup(sess); 542 printf("%s: Unable to c reate callback connection toservice %s (%s)\n",536 printf("%s: Unable to communicate with service %s (%s)\n", 543 537 NAME, svc, str_error(rc)); 544 return NULL;545 } 546 547 return sess;538 return rc; 539 } 540 541 return EOK; 548 542 } 549 543 … … 574 568 static bool console_srv_init(char *input_svc, char *output_svc) 575 569 { 570 int rc; 571 576 572 /* Connect to input service */ 577 input_sess= input_connect(input_svc);578 if ( input_sess == NULL)573 rc = input_connect(input_svc); 574 if (rc != EOK) 579 575 return false; 580 576 … … 586 582 /* Register server */ 587 583 async_set_client_connection(client_connection); 588 intrc = loc_server_register(NAME);584 rc = loc_server_register(NAME); 589 585 if (rc != EOK) { 590 586 printf("%s: Unable to register server (%s)\n", NAME,
Note:
See TracChangeset
for help on using the changeset viewer.