From: Olaf Wintermann Date: Sat, 15 Jan 2022 12:09:27 +0000 (+0100) Subject: redirect key events to the player window X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=1a310acf08a2d12cba26c745c0d29030238675f0;p=uwplayer.git redirect key events to the player window --- diff --git a/application/player.c b/application/player.c index 381132e..9e47049 100644 --- a/application/player.c +++ b/application/player.c @@ -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)); - } - } + } diff --git a/application/window.c b/application/window.c index 8132f86..da0b04c 100644 --- a/application/window.c +++ b/application/window.c @@ -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")); diff --git a/application/window.h b/application/window.h index 402b6ed..03da44e 100644 --- a/application/window.h +++ b/application/window.h @@ -40,7 +40,7 @@ typedef struct Player { int status; bool isactive; bool isstarted; - + Window window; double playback_time; int width; int height;