]> uap-core.de Git - uwplayer.git/commitdiff
redirect key events to the player window
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 15 Jan 2022 12:09:27 +0000 (13:09 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 15 Jan 2022 12:09:27 +0000 (13:09 +0100)
application/player.c
application/window.c
application/window.h

index 381132ef5b40fbeaba08becee2e845a7b544578d..9e470497bede5be35d55ceb47586cff241a2ce52 100644 (file)
@@ -394,6 +394,23 @@ static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid) {
     }
 }
 
+static Boolean get_player_window(XtPointer data) {
+    Player *p = data;
+    MainWindow *win = GetMainWindow();
+    
+    Widget player_wid = win->player_widget;
+    Window root, parent;
+    Window *child;
+    unsigned int nchild;
+    XQueryTree(XtDisplay(player_wid), XtWindow(player_wid), &root, &parent, &child, &nchild);
+    if(nchild > 0) {
+        p->window = child[0];
+        XFree(child);
+    }
+    
+    return 0;
+}
+
 static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) {
     if(!json_strcmp(event, "property-change")) {
         JSONValue *name = json_obj_get(&v->value.object, "name");
@@ -411,6 +428,8 @@ static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) {
                     "{ \"command\": [\"set_property\", \"keep-open\", true] }\n";
         write(p->ipc, cmd, strlen(cmd));
         p->isstarted = TRUE;
+        
+        AppExecProc(get_player_window, p);
     }
 }
 
@@ -510,34 +529,5 @@ void PlayerEOF(Player *p) {
 }
 
 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 8132f86aedb0ff425ca4932ab3e32b9535e4de81..da0b04c4e124c7774970cb3ca6b6eefc7be2667f 100644 (file)
@@ -65,6 +65,50 @@ static void playerWidgetInputCB(Widget widget, XtPointer u, XtPointer c) {
     }
 }
 
+static void playerEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
+    MainWindow *win = data;
+    if(!win->player || win->player->window == 0) return;
+    
+    /*
+    if(event->type == EnterNotify) {
+        printf("enter: grab pointer\n");
+        
+        XtGrabPointer(
+                win->player_widget,
+                True,
+                ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
+                GrabModeAsync,
+                GrabModeAsync,
+                None,
+                None,
+                CurrentTime);
+        
+        return;
+    }
+    if(event->type == LeaveNotify) {
+        printf("leave\n");
+        XtUngrabPointer(win->player_widget, CurrentTime); 
+        return;
+    }
+    
+    if(event->type == MotionNotify) {
+        static int testv = 0;
+        printf("test %d\n", testv++);
+    }
+    */
+    
+    if(event->type == KeyPress || event->type == KeyRelease) {
+        // redirect key events to the player window
+        event->xkey.window = win->player->window;
+        XSendEvent(
+                XtDisplay(win->player_widget),
+                win->player->window,
+                True,
+                0,
+                event);
+    }
+}
+
 MainWindow* WindowCreate(Display *display) {
     Arg args[32];
     int n;
@@ -125,6 +169,10 @@ MainWindow* WindowCreate(Display *display) {
     XtManageChild(window->player_widget);
     XtAddCallback(window->player_widget, XmNinputCallback, playerWidgetInputCB, window);
     XmProcessTraversal(window->player_widget, XmTRAVERSE_CURRENT);
+    XtAddEventHandler(window->player_widget, PointerMotionMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask |
+                 EnterWindowMask | KeyPressMask | KeyReleaseMask |
+                  LeaveWindowMask, FALSE, playerEH, window);
+    
     
     // get F keycode
     keycodeF = XKeysymToKeycode(XtDisplay(window->window), XStringToKeysym("F"));
index 402b6ed10e7e3648cf535e0f35081e096572014e..03da44e734da4d7ade8afcdcb675246d211b91ea 100644 (file)
@@ -40,7 +40,7 @@ typedef struct Player {
     int status;
     bool isactive;
     bool isstarted;
-    
+    Window window;
     double playback_time;
     int width;
     int height;