summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphintuka <phintuka>2006-06-06 07:57:41 +0000
committerphintuka <phintuka>2006-06-06 07:57:41 +0000
commit25aaaf0fa23288da7ff23607e48e7f5f20bc6662 (patch)
treee61a381d152926799aff6c8753fad5f98a590484
parent468ff2acc8d288cde9644c968bf66410fc5fca49 (diff)
downloadxineliboutput-25aaaf0fa23288da7ff23607e48e7f5f20bc6662.tar.gz
xineliboutput-25aaaf0fa23288da7ff23607e48e7f5f20bc6662.tar.bz2
Keyboard handling updates
-rw-r--r--xine_frontend_main.c110
-rw-r--r--xine_sxfe_frontend.c36
2 files changed, 102 insertions, 44 deletions
diff --git a/xine_frontend_main.c b/xine_frontend_main.c
index b265958c..e9db2ae1 100644
--- a/xine_frontend_main.c
+++ b/xine_frontend_main.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_frontend_main.c,v 1.2 2006-06-04 11:00:04 phintuka Exp $
+ * $Id: xine_frontend_main.c,v 1.3 2006-06-06 07:57:41 phintuka Exp $
*
*/
@@ -39,11 +39,75 @@ pthread_t kbd_thread;
struct termios tm, saved_tm;
volatile int terminate_key_pressed = 0;
-void *kbd_receiver_thread(void *fe)
+static int read_key(void)
{
+ /* from vdr, remote.c */
struct pollfd pfd;
- char ch;
- int err;
+ pfd.fd = STDIN_FILENO;
+ pfd.events = POLLIN;
+ if(poll(&pfd, 1, 50) == 1) {
+ unsigned char ch = 0;
+ int r = read(STDIN_FILENO, &ch, 1);
+ if (r == 1)
+ return (int)ch;
+ if (r < 0) {
+ LOGERR("read_key: read failed");
+ return -2;
+ }
+ }
+ return -1;
+}
+
+static uint64_t read_key_seq(void)
+{
+ /* from vdr, remote.c */
+ uint64_t k = 0;
+ int key1;
+
+ if ((key1 = read_key()) >= 0) {
+ k = key1;
+ if (key1 == 0x1B) {
+ // Start of escape sequence
+ if ((key1 = read_key()) >= 0) {
+ k <<= 8;
+ k |= key1 & 0xFF;
+ switch (key1) {
+ case 0x4F: // 3-byte sequence
+ if ((key1 = read_key()) >= 0) {
+ k <<= 8;
+ k |= key1 & 0xFF;
+ }
+ break;
+ case 0x5B: // 3- or more-byte sequence
+ if ((key1 = read_key()) >= 0) {
+ k <<= 8;
+ k |= key1 & 0xFF;
+ switch (key1) {
+ case 0x31 ... 0x3F: // more-byte sequence
+ case 0x5B: // strange, may apparently occur
+ do {
+ if ((key1 = read_key()) < 0)
+ break; // Sequence ends here
+ k <<= 8;
+ k |= key1 & 0xFF;
+ } while (key1 != 0x7E);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ if(key1==-2)
+ return 0xffff;
+ return k;
+}
+
+static void *kbd_receiver_thread(void *fe)
+{
+ uint64_t code = 0;
+ char str[64];
terminate_key_pressed = 0;
@@ -58,31 +122,23 @@ void *kbd_receiver_thread(void *fe)
}
do {
- errno = 0;
- pfd.fd = STDIN_FILENO;
- pfd.events = POLLIN;
- err = poll(&pfd, 1, 250);
- if(err==1) {
- if(1 == read(STDIN_FILENO, &ch, 1)) {
- /* forward keyboard input to server */
- uint64_t code = ch;
- char str[64];
- while(poll(&pfd,1,0) == 1 && read(STDIN_FILENO,&ch,1) == 1)
- code = (code<<8) | (ch & 0xff);
-
- if(code == 27) { //ch == 'q' || ch == 'Q' /*|| ch == 27*/) {
- terminate_key_pressed = 1;
- break;
- } //else {
-
- snprintf(str, sizeof(str), "%016" PRIX64, code);
- if(find_input((fe_t*)fe))
- process_xine_keypress(((fe_t*)fe)->input, "KBD", str, 0, 0);
- }
+ errno = 0;
+ code = read_key_seq();
+ if(code == 0)
+ continue;
+ if(code == 27) {
+ terminate_key_pressed = 1;
+ break;
}
-
- } while(err >= 0 || errno == EINTR);
+ if(code == 0xffff)
+ break;
+
+ snprintf(str, sizeof(str), "%016" PRIX64, code);
+ if(find_input((fe_t*)fe))
+ process_xine_keypress(((fe_t*)fe)->input, "KBD", str, 0, 0);
+ } while(!terminate_key_pressed && code != 0xffff);
+
LOGMSG("Keyboard thread terminated");
tcsetattr(STDIN_FILENO, TCSANOW, &saved_tm);
pthread_exit(NULL);
diff --git a/xine_sxfe_frontend.c b/xine_sxfe_frontend.c
index 98f3434a..621fd582 100644
--- a/xine_sxfe_frontend.c
+++ b/xine_sxfe_frontend.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_sxfe_frontend.c,v 1.3 2006-06-04 11:40:58 phintuka Exp $
+ * $Id: xine_sxfe_frontend.c,v 1.4 2006-06-06 07:57:41 phintuka Exp $
*
*/
@@ -465,20 +465,21 @@ static int sxfe_run(frontend_t *this_gen)
struct pollfd pfd[2];
pfd[0].fd = ConnectionNumber(this->display);
pfd[0].events = POLLIN;
- if(poll(pfd, 1, 500) < 1 || !(pfd[0].revents & POLLIN)) {
+ if(poll(pfd, 1, 50) < 1 || !(pfd[0].revents & POLLIN)) {
return 1;
}
}
-
- XNextEvent (this->display, &event);
-
- switch (event.type) {
- case Expose:
- if (event.xexpose.count == 0)
- xine_gui_send_vo_data (this->stream, XINE_GUI_SEND_EXPOSE_EVENT, &event);
- break;
- case ConfigureNotify:
+ while(keep_going && XPending(this->display) > 0) {
+ XNextEvent (this->display, &event);
+
+ switch (event.type) {
+ case Expose:
+ if (event.xexpose.count == 0)
+ xine_gui_send_vo_data (this->stream, XINE_GUI_SEND_EXPOSE_EVENT, &event);
+ break;
+
+ case ConfigureNotify:
{
XConfigureEvent *cev = (XConfigureEvent *) &event;
Window tmp_win;
@@ -499,8 +500,8 @@ static int sxfe_run(frontend_t *this_gen)
break;
}
- case KeyPress:
- case KeyRelease:
+ case KeyPress:
+ case KeyRelease:
{
XKeyEvent *kevent = (XKeyEvent *) &event;
KeySym ks;
@@ -525,7 +526,7 @@ static int sxfe_run(frontend_t *this_gen)
}
break;
- case ClientMessage:
+ case ClientMessage:
{
XClientMessageEvent *cmessage = (XClientMessageEvent *) &event;
if ( cmessage->message_type == this->sxfe_interrupt )
@@ -535,11 +536,12 @@ static int sxfe_run(frontend_t *this_gen)
/* we got a window deletion message from out window manager.*/
keep_going=0;
}
+ }
+
+ if (event.type == this->completion_event)
+ xine_gui_send_vo_data (this->stream, XINE_GUI_SEND_COMPLETION_EVENT, &event);
}
- if (event.type == this->completion_event)
- xine_gui_send_vo_data (this->stream, XINE_GUI_SEND_COMPLETION_EVENT, &event);
-
return keep_going;
}