}
}
+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");
"{ \"command\": [\"set_property\", \"keep-open\", true] }\n";
write(p->ipc, cmd, strlen(cmd));
p->isstarted = TRUE;
+
+ AppExecProc(get_player_window, 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));
- }
- }
+
}
}
}
+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;
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"));