]> uap-core.de Git - uwplayer.git/commitdiff
handle key events in the player widget and pass them to mpv
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 14 Jan 2022 11:14:43 +0000 (12:14 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 14 Jan 2022 11:14:43 +0000 (12:14 +0100)
application/player.c
application/player.h
application/window.c

index 7620a63a5be68b5608b23abbfaacf276f9f5ebd0..381132ef5b40fbeaba08becee2e845a7b544578d 100644 (file)
@@ -508,3 +508,36 @@ void PlayerEOF(Player *p) {
     char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n";
     write(p->ipc, cmd, strlen(cmd));
 }
+
+void PlayerHandleInput(MainWindow *win, Player *p, XmDrawingAreaCallbackStruct *cb) {
+    if(cb->event->type == KeyPress) {
+        XKeyEvent *xkey = &cb->event->xkey;
+
+        static XComposeStatus compose = {NULL, 0};
+        char chars[8];
+        KeySym keysym;
+        int nchars;
+        
+        char keystr[64];
+        keystr[0] = 0;
+
+        nchars = XLookupString(xkey, chars, 8, &keysym, &compose);
+        if(nchars == 1) {
+            if(chars[0] >= 'a' && chars[0] <= 'z') {
+                keystr[0] = chars[0];
+                keystr[1] = 0;
+            } else if(chars[0] == ' ') {
+                memcpy(keystr, "space", 6);
+            } 
+        }
+        
+        if(keystr[0] != 0) {
+            char cmdbuf[STR_BUFSIZE];
+            if(snprintf(cmdbuf, STR_BUFSIZE, "{ \"command\": [\"keypress\", \"%s\"] }\n", keystr) >= STR_BUFSIZE) {
+                // error: buffer to small
+                return;
+            }
+            write(p->ipc, cmdbuf, strlen(cmdbuf));
+        }
+    } 
+}
index 98584919e27e5d8231211ac93654048f22d6fc81..8f47e83164c5128c11ee9cc458b92b9ca2aa5f1e 100644 (file)
@@ -44,6 +44,7 @@ void PlayerDestroy(Player *p);
 
 void PlayerEOF(Player *p);
 
+void PlayerHandleInput(MainWindow *win, Player *p, XmDrawingAreaCallbackStruct *cb);
 
 #ifdef __cplusplus
 }
index dd8700c10fc71593fa3a87f412cde7ffa5e379d5..8132f86aedb0ff425ca4932ab3e32b9535e4de81 100644 (file)
@@ -56,6 +56,15 @@ static void resizeEH(Widget widget, XtPointer data, XEvent *event, Boolean *disp
     WindowAdjustAspectRatio(data);
 }
 
+static void playerWidgetInputCB(Widget widget, XtPointer u, XtPointer c) {
+    MainWindow *win = u;
+    XmDrawingAreaCallbackStruct *cb = c;
+    
+    if(win->player && win->player->isactive) {
+        PlayerHandleInput(win, win->player, cb);
+    }
+}
+
 MainWindow* WindowCreate(Display *display) {
     Arg args[32];
     int n;
@@ -114,6 +123,7 @@ MainWindow* WindowCreate(Display *display) {
     XtSetArg(args[n], XmNbackground, BlackPixelOfScreen(XtScreen(window->window))); n++;
     window->player_widget = XmCreateDrawingArea(container, "player", args, n);
     XtManageChild(window->player_widget);
+    XtAddCallback(window->player_widget, XmNinputCallback, playerWidgetInputCB, window);
     XmProcessTraversal(window->player_widget, XmTRAVERSE_CURRENT);
     
     // get F keycode