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));
+ }
+ }
+}
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;
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