diff options
| author | Joakim Verona | 2011-07-14 23:16:18 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-07-14 23:16:18 +0200 |
| commit | c43c0a65b7b7ef5899462a997734299aad3e9a00 (patch) | |
| tree | 303832ba334bb45d679c24e9a0547ebab3fb4940 /src | |
| parent | 42f051946e70bb5e6ad407b85d003040d9ba5006 (diff) | |
| download | emacs-c43c0a65b7b7ef5899462a997734299aad3e9a00.tar.gz emacs-c43c0a65b7b7ef5899462a997734299aad3e9a00.zip | |
begin moving xwidget storage to lisp. button test shows again since tag 0.1, so its not a completely useless version, but since the xwidget identity concept now changed from int to pointer, lots of code was commented out and needs rework
Diffstat (limited to 'src')
| -rw-r--r-- | src/dispextern.h | 8 | ||||
| -rw-r--r-- | src/xdisp.c | 19 | ||||
| -rw-r--r-- | src/xterm.c | 14 | ||||
| -rw-r--r-- | src/xwidget-attic.c | 184 | ||||
| -rw-r--r-- | src/xwidget.c | 404 | ||||
| -rw-r--r-- | src/xwidget.h | 48 |
6 files changed, 365 insertions, 312 deletions
diff --git a/src/dispextern.h b/src/dispextern.h index 44f865d3149..31ad7af4a84 100644 --- a/src/dispextern.h +++ b/src/dispextern.h | |||
| @@ -435,7 +435,7 @@ struct glyph | |||
| 435 | /* Image ID for image glyphs (type == IMAGE_GLYPH). */ | 435 | /* Image ID for image glyphs (type == IMAGE_GLYPH). */ |
| 436 | int img_id; | 436 | int img_id; |
| 437 | 437 | ||
| 438 | unsigned xwidget_id; | 438 | struct xwidget* xwidget; |
| 439 | 439 | ||
| 440 | /* Sub-structure for type == STRETCH_GLYPH. */ | 440 | /* Sub-structure for type == STRETCH_GLYPH. */ |
| 441 | struct | 441 | struct |
| @@ -1303,7 +1303,7 @@ struct glyph_string | |||
| 1303 | /* Image, if any. */ | 1303 | /* Image, if any. */ |
| 1304 | struct image *img; | 1304 | struct image *img; |
| 1305 | 1305 | ||
| 1306 | int xwidget_id; | 1306 | struct xwidget* xwidget; |
| 1307 | 1307 | ||
| 1308 | /* Slice */ | 1308 | /* Slice */ |
| 1309 | struct glyph_slice slice; | 1309 | struct glyph_slice slice; |
| @@ -2245,7 +2245,7 @@ struct it | |||
| 2245 | /* method == GET_FROM_XWIDGET */ | 2245 | /* method == GET_FROM_XWIDGET */ |
| 2246 | struct { | 2246 | struct { |
| 2247 | Lisp_Object object; | 2247 | Lisp_Object object; |
| 2248 | int xwidget_id; | 2248 | struct xwidget* xwidget; |
| 2249 | } xwidget; | 2249 | } xwidget; |
| 2250 | 2250 | ||
| 2251 | } u; | 2251 | } u; |
| @@ -2368,7 +2368,7 @@ struct it | |||
| 2368 | int image_id; | 2368 | int image_id; |
| 2369 | 2369 | ||
| 2370 | /* If what == IT_XWIDGET*/ | 2370 | /* If what == IT_XWIDGET*/ |
| 2371 | int xwidget_id; | 2371 | struct xwidget* xwidget; |
| 2372 | 2372 | ||
| 2373 | 2373 | ||
| 2374 | /* Values from `slice' property. */ | 2374 | /* Values from `slice' property. */ |
diff --git a/src/xdisp.c b/src/xdisp.c index c662557845a..31506e2247b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -4371,8 +4371,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object, | |||
| 4371 | it->object = NILP (object) ? it->w->buffer : object; | 4371 | it->object = NILP (object) ? it->w->buffer : object; |
| 4372 | *position = start_pos; | 4372 | *position = start_pos; |
| 4373 | 4373 | ||
| 4374 | it->xwidget_id=lookup_xwidget(value); | 4374 | it->xwidget = lookup_xwidget(value); |
| 4375 | assert_valid_xwidget_id(it->xwidget_id,"handle_single_display_spec"); | ||
| 4376 | } | 4375 | } |
| 4377 | #ifdef HAVE_WINDOW_SYSTEM | 4376 | #ifdef HAVE_WINDOW_SYSTEM |
| 4378 | else //if nothing else, its an image | 4377 | else //if nothing else, its an image |
| @@ -6612,9 +6611,9 @@ static int | |||
| 6612 | next_element_from_xwidget (struct it *it) | 6611 | next_element_from_xwidget (struct it *it) |
| 6613 | { | 6612 | { |
| 6614 | it->what = IT_XWIDGET; | 6613 | it->what = IT_XWIDGET; |
| 6615 | assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget"); | 6614 | //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget"); |
| 6616 | //this is shaky because why do we set "what" if we dont set the other parts?? | 6615 | //this is shaky because why do we set "what" if we dont set the other parts?? |
| 6617 | printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id); | 6616 | //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id); |
| 6618 | return 1; | 6617 | return 1; |
| 6619 | } | 6618 | } |
| 6620 | 6619 | ||
| @@ -16449,7 +16448,7 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area) | |||
| 16449 | ? 'S' | 16448 | ? 'S' |
| 16450 | : '-')), | 16449 | : '-')), |
| 16451 | glyph->pixel_width, | 16450 | glyph->pixel_width, |
| 16452 | glyph->u.xwidget_id, | 16451 | glyph->u.xwidget, |
| 16453 | '.', | 16452 | '.', |
| 16454 | glyph->face_id, | 16453 | glyph->face_id, |
| 16455 | glyph->left_box_line_p, | 16454 | glyph->left_box_line_p, |
| @@ -21002,8 +21001,8 @@ fill_xwidget_glyph_string (struct glyph_string *s) | |||
| 21002 | s->font = s->face->font; | 21001 | s->font = s->face->font; |
| 21003 | s->width = s->first_glyph->pixel_width; | 21002 | s->width = s->first_glyph->pixel_width; |
| 21004 | s->ybase += s->first_glyph->voffset; | 21003 | s->ybase += s->first_glyph->voffset; |
| 21005 | s->xwidget_id=s->first_glyph->u.xwidget_id; | 21004 | s->xwidget = s->first_glyph->u.xwidget; |
| 21006 | assert_valid_xwidget_id(s->xwidget_id,"fill_xwidget_glyph_string"); | 21005 | //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string"); |
| 21007 | } | 21006 | } |
| 21008 | 21007 | ||
| 21009 | 21008 | ||
| @@ -22136,7 +22135,7 @@ produce_xwidget_glyph (struct it *it) | |||
| 22136 | /* Make sure X resources of the face is loaded. */ | 22135 | /* Make sure X resources of the face is loaded. */ |
| 22137 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | 22136 | PREPARE_FACE_FOR_DISPLAY (it->f, face); |
| 22138 | 22137 | ||
| 22139 | xw = xwidget_from_id(it->xwidget_id); | 22138 | xw = it->xwidget; |
| 22140 | it->ascent = it->phys_ascent = glyph_ascent = xw->height/2; | 22139 | it->ascent = it->phys_ascent = glyph_ascent = xw->height/2; |
| 22141 | it->descent = xw->height/2; | 22140 | it->descent = xw->height/2; |
| 22142 | it->phys_descent = it->descent; | 22141 | it->phys_descent = it->descent; |
| @@ -22194,8 +22193,8 @@ produce_xwidget_glyph (struct it *it) | |||
| 22194 | glyph->padding_p = 0; | 22193 | glyph->padding_p = 0; |
| 22195 | glyph->glyph_not_available_p = 0; | 22194 | glyph->glyph_not_available_p = 0; |
| 22196 | glyph->face_id = it->face_id; | 22195 | glyph->face_id = it->face_id; |
| 22197 | glyph->u.xwidget_id = it->xwidget_id; | 22196 | glyph->u.xwidget = it->xwidget; |
| 22198 | assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph"); | 22197 | //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph"); |
| 22199 | glyph->font_type = FONT_TYPE_UNKNOWN; | 22198 | glyph->font_type = FONT_TYPE_UNKNOWN; |
| 22200 | ++it->glyph_row->used[area]; | 22199 | ++it->glyph_row->used[area]; |
| 22201 | } | 22200 | } |
diff --git a/src/xterm.c b/src/xterm.c index 9bdbc1f7d34..58b326fc227 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -5834,20 +5834,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr, | |||
| 5834 | inev.ie.kind = NO_EVENT; | 5834 | inev.ie.kind = NO_EVENT; |
| 5835 | inev.ie.arg = Qnil; | 5835 | inev.ie.arg = Qnil; |
| 5836 | 5836 | ||
| 5837 | /*try to let events escape to xwidgets if xwidget_owns_kbd. not as easy as it sounds... */ | ||
| 5838 | if(xwidget_owns_kbd){ | ||
| 5839 | printf("xwidgets own events now!\n"); | ||
| 5840 | //according to xembed spec it seems like the toolkit is responsible for forwarding of events, so | ||
| 5841 | //try to let gtk have the event now | ||
| 5842 | *finish = 0; | ||
| 5843 | |||
| 5844 | /*FINISH is X_EVENT_GOTO_OUT if caller should stop reading events. | ||
| 5845 | *FINISH is zero if caller should continue reading events. | ||
| 5846 | *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.*/ | ||
| 5847 | goto OTHER; | ||
| 5848 | } | ||
| 5849 | |||
| 5850 | |||
| 5851 | 5837 | ||
| 5852 | if (pending_event_wait.eventtype == event.type) | 5838 | if (pending_event_wait.eventtype == event.type) |
| 5853 | pending_event_wait.eventtype = 0; /* Indicates we got it. */ | 5839 | pending_event_wait.eventtype = 0; /* Indicates we got it. */ |
diff --git a/src/xwidget-attic.c b/src/xwidget-attic.c index a49623124c5..b80b57c8e07 100644 --- a/src/xwidget-attic.c +++ b/src/xwidget-attic.c | |||
| @@ -314,3 +314,187 @@ void webkit_osr_redraw_child ( struct xwidget* xw, GtkWidget *widget) | |||
| 314 | cairo_destroy (cr); | 314 | cairo_destroy (cr); |
| 315 | #endif | 315 | #endif |
| 316 | } | 316 | } |
| 317 | |||
| 318 | |||
| 319 | |||
| 320 | DEFUN ("xwidget-embed-steal-window", Fxwidget_embed_steal_window, Sxwidget_embed_steal_window, 2, 2, 0, | ||
| 321 | doc: /* Tell existing embed xwidget to steal other window id. This is based on a deprecated method in GTK and doesnt work too well.*/ | ||
| 322 | ) | ||
| 323 | (Lisp_Object xwidget_id, Lisp_Object window_id) | ||
| 324 | { | ||
| 325 | int iwindow_id; | ||
| 326 | struct xwidget* xw = xid2xw(xwidget_id); | ||
| 327 | |||
| 328 | CHECK_NUMBER (window_id); | ||
| 329 | iwindow_id = XFASTINT (window_id); | ||
| 330 | |||
| 331 | // gtk_socket_steal(GTK_SOCKET(xw->widget),iwindow_id); | ||
| 332 | //try adding proper gtk plugs instead, i never once had "steal" work | ||
| 333 | ///////// gtk_socket_add_id (GTK_SOCKET (xw->widget), iwindow_id); /////TODO MVC | ||
| 334 | //add_id annoyingly odesnt work either. the only working option | ||
| 335 | //seems to be clients that plug into the sockets, and so far only emacs and mplayer | ||
| 336 | //oenvrml | ||
| 337 | return Qnil; | ||
| 338 | } | ||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | DEFUN("xwidget-info", Fxwidget_info , Sxwidget_info, 1,1,0, doc: /* get xwidget props */) | ||
| 343 | (Lisp_Object xwidget_id) | ||
| 344 | { | ||
| 345 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 346 | Lisp_Object info; | ||
| 347 | |||
| 348 | info = Fmake_vector (make_number (4), Qnil); | ||
| 349 | XVECTOR (info)->contents[0] = make_number(xw->id); | ||
| 350 | XVECTOR (info)->contents[1] = xw->type; | ||
| 351 | XVECTOR (info)->contents[2] = make_number(xw->width); | ||
| 352 | XVECTOR (info)->contents[3] = make_number(xw->height); | ||
| 353 | |||
| 354 | |||
| 355 | return info; | ||
| 356 | } | ||
| 357 | |||
| 358 | |||
| 359 | |||
| 360 | //xterm.c listens to xwidget_owns_kbd and tries to not eat events when its set | ||
| 361 | int xwidget_owns_kbd = 0; | ||
| 362 | DEFUN ("xwidget-set-keyboard-grab", Fxwidget_set_keyboard_grab, Sxwidget_set_keyboard_grab, 2, 2, 0, doc: /* set unset kbd grab for xwidget. */ | ||
| 363 | ) | ||
| 364 | (Lisp_Object xwidget_id, Lisp_Object kbd_grab) | ||
| 365 | { | ||
| 366 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 367 | int xid, kbd_flag; | ||
| 368 | |||
| 369 | CHECK_NUMBER (kbd_grab); | ||
| 370 | kbd_flag = XFASTINT (kbd_grab); | ||
| 371 | |||
| 372 | |||
| 373 | |||
| 374 | printf ("kbd grab: %d %d\n", xid, kbd_flag); | ||
| 375 | if (kbd_flag) | ||
| 376 | { | ||
| 377 | //int rv=gtk_widget_activate(xw->widget); //ok, but how deactivate? | ||
| 378 | //printf("activation:%d\n",rv); | ||
| 379 | // gtk_window_present(GTK_WINDOW(xw->widget)); | ||
| 380 | //gtk_widget_grab_focus(xw->widget); | ||
| 381 | // gtk_socket_windowing_update_active (xw->widget,1); | ||
| 382 | // GDK_WINDOW_XWINDOW (GTK_WIDGET (socket)->window) | ||
| 383 | //FRAME_X_OUTPUT (f)->widget | ||
| 384 | // gdk_keyboard_grab(xw->widget,TRUE,GDK_CURRENT_TIME); | ||
| 385 | |||
| 386 | /* GtkWidget *parent = gtk_widget_get_parent (xw->widget); */ | ||
| 387 | /* GtkWidget *lastparent; */ | ||
| 388 | /* for (lastparent = parent; parent = gtk_widget_get_parent (parent); */ | ||
| 389 | /* parent == NULL); */ | ||
| 390 | |||
| 391 | /* gtk_container_set_focus_child (GTK_CONTAINER (lastparent), xw->widget); */ | ||
| 392 | |||
| 393 | ////gtk_container_set_focus_child (GTK_CONTAINER (xw->widgetwindow), xw->widget); //TODO MVC | ||
| 394 | |||
| 395 | xwidget_owns_kbd = TRUE; | ||
| 396 | } | ||
| 397 | else | ||
| 398 | { | ||
| 399 | xwidget_owns_kbd = FALSE; | ||
| 400 | } | ||
| 401 | /* | ||
| 402 | gdk_keyboard_grab(xw->widget,TRUE,GDK_CURRENT_TIME); | ||
| 403 | else | ||
| 404 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); | ||
| 405 | */ | ||
| 406 | return Qnil; | ||
| 407 | } | ||
| 408 | |||
| 409 | |||
| 410 | |||
| 411 | |||
| 412 | |||
| 413 | |||
| 414 | //lowlevel fn mostly cloned from xembed_send_message() | ||
| 415 | void | ||
| 416 | xwidget_key_send_message (struct frame *f, | ||
| 417 | Window destination_window, | ||
| 418 | int keycode, int keypress, int modifiers) | ||
| 419 | { | ||
| 420 | |||
| 421 | XKeyEvent event; | ||
| 422 | //segfaults: | ||
| 423 | /* xwidget_key_send_message (f=0x0, destination_window=0, keycode=65, keypress=1, */ | ||
| 424 | /* modifiers=0) at xwidget.c:332 */ | ||
| 425 | /* 332 event.display = FRAME_X_DISPLAY (f); */ | ||
| 426 | |||
| 427 | event.display = FRAME_X_DISPLAY (f); | ||
| 428 | event.window = destination_window; | ||
| 429 | event.root = FRAME_X_WINDOW (f); | ||
| 430 | event.subwindow = None; | ||
| 431 | event.time = CurrentTime; | ||
| 432 | event.x = 1; | ||
| 433 | event.y = 1; | ||
| 434 | event.x_root = 1; | ||
| 435 | event.y_root = 1; | ||
| 436 | event.same_screen = TRUE; | ||
| 437 | |||
| 438 | event.type = keypress ? KeyPress : KeyRelease; | ||
| 439 | event.keycode = keycode; | ||
| 440 | event.state = modifiers; | ||
| 441 | |||
| 442 | XSendEvent (event.display, event.window, TRUE, KeyPressMask, | ||
| 443 | (XEvent *) & event); | ||
| 444 | } | ||
| 445 | |||
| 446 | //using "accessible" interfaces seems expensive | ||
| 447 | //pkg-config --cflags cspi-1.0 | ||
| 448 | //#include <at-spi-1.0/cspi/spi.h> | ||
| 449 | |||
| 450 | DEFUN ("xwidget-send-keyboard-event", Fxwidget_send_keyboard_event, Sxwidget_send_keyboard_event, 2, 2, 0, doc:/* synthesize a kbd event for a xwidget. */ | ||
| 451 | ) | ||
| 452 | (Lisp_Object xwidget_id, Lisp_Object keydescriptor) | ||
| 453 | { | ||
| 454 | int keyval; | ||
| 455 | char *keystring = ""; | ||
| 456 | FRAME_PTR f; | ||
| 457 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 458 | GdkWindow *window; | ||
| 459 | XID xid; | ||
| 460 | |||
| 461 | /* TODO MVC | ||
| 462 | f = (FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA); | ||
| 463 | |||
| 464 | //GdkWindow* window=gtk_widget_get_window(xw->widget); //event winds up in emacs | ||
| 465 | |||
| 466 | //TODO assert xw is a gtk_socket or THIS WILL FAIL GLORIOUSLY | ||
| 467 | window = gtk_socket_get_plug_window (GTK_SOCKET (xw->widget)); | ||
| 468 | //the event gets eaten somewhere. | ||
| 469 | //i suspect you just cant send an event to a child window and not have emacs eat it. | ||
| 470 | //but if this were true the event should pop to emacs right? | ||
| 471 | |||
| 472 | |||
| 473 | xid = gdk_x11_drawable_get_xid (window); | ||
| 474 | |||
| 475 | printf ("xwidget-send-keyboard-event %d %d\n", window, xid); | ||
| 476 | |||
| 477 | xwidget_key_send_message (f, xid, 38, 1, 0); //38 is 'a' HACK for now | ||
| 478 | xwidget_key_send_message (f, xid, 38, 0, 0); | ||
| 479 | */ | ||
| 480 | return Qnil; | ||
| 481 | } | ||
| 482 | |||
| 483 | |||
| 484 | void | ||
| 485 | assert_valid_xwidget_id (int id, char *str) | ||
| 486 | { | ||
| 487 | if (id < 0 || id > MAX_XWIDGETS) | ||
| 488 | { | ||
| 489 | printf ("broken xwidgetid:%d %s\n", id, str); | ||
| 490 | abort (); | ||
| 491 | } | ||
| 492 | } | ||
| 493 | |||
| 494 | |||
| 495 | struct xwidget * | ||
| 496 | xwidget_from_id (int id) | ||
| 497 | { | ||
| 498 | assert_valid_xwidget_id (id, "xwidget_from_id"); | ||
| 499 | return &xwidgets[id]; | ||
| 500 | } | ||
diff --git a/src/xwidget.c b/src/xwidget.c index e82864e2220..f4362dd25ef 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -102,11 +102,26 @@ | |||
| 102 | //would need to be hashtables or something | 102 | //would need to be hashtables or something |
| 103 | 103 | ||
| 104 | #define MAX_XWIDGETS 100 | 104 | #define MAX_XWIDGETS 100 |
| 105 | struct xwidget xwidgets[MAX_XWIDGETS]; | ||
| 106 | struct xwidget_view xwidget_views[MAX_XWIDGETS]; | 105 | struct xwidget_view xwidget_views[MAX_XWIDGETS]; |
| 107 | 106 | ||
| 107 | //TODO embryo of lisp allocators for xwidgets | ||
| 108 | //TODO xwidget* should be Lisp_xwidget* | ||
| 109 | struct xwidget* | ||
| 110 | allocate_xwidget (void) | ||
| 111 | { | ||
| 112 | return ALLOCATE_PSEUDOVECTOR (struct xwidget, height, PVEC_OTHER); | ||
| 113 | } | ||
| 114 | |||
| 115 | //TODO xwidget_view* should be Lisp_xwidget_view* | ||
| 116 | struct xwidget_view* | ||
| 117 | allocate_xwidget_view (void) | ||
| 118 | { | ||
| 119 | return ALLOCATE_PSEUDOVECTOR (struct xwidget_view, redisplayed, PVEC_OTHER); | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 108 | Lisp_Object Qxwidget; | 123 | Lisp_Object Qxwidget; |
| 109 | Lisp_Object Qxwidget_id; | 124 | Lisp_Object Qcxwidget; |
| 110 | Lisp_Object Qtitle; | 125 | Lisp_Object Qtitle; |
| 111 | Lisp_Object Qxwidget_set_keyboard_grab; | 126 | Lisp_Object Qxwidget_set_keyboard_grab; |
| 112 | Lisp_Object Qxwidget_embed_steal_window; | 127 | Lisp_Object Qxwidget_embed_steal_window; |
| @@ -123,6 +138,65 @@ extern Lisp_Object QCwidth, QCheight; | |||
| 123 | 138 | ||
| 124 | struct xwidget_view* xwidget_view_lookup(struct xwidget* xw, struct window *w); | 139 | struct xwidget_view* xwidget_view_lookup(struct xwidget* xw, struct window *w); |
| 125 | Lisp_Object xwidget_spec_value ( Lisp_Object spec, Lisp_Object key, int *found); | 140 | Lisp_Object xwidget_spec_value ( Lisp_Object spec, Lisp_Object key, int *found); |
| 141 | gboolean webkit_osr_damage_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) ; | ||
| 142 | |||
| 143 | DEFUN ("make-xwidget", Fmake_xwidget, Smake_xwidget, 7, 7, 0, | ||
| 144 | doc: /* xw */ | ||
| 145 | ) | ||
| 146 | (Lisp_Object beg, Lisp_Object end, | ||
| 147 | Lisp_Object type, | ||
| 148 | Lisp_Object title, | ||
| 149 | Lisp_Object width, Lisp_Object height, | ||
| 150 | Lisp_Object data) | ||
| 151 | { | ||
| 152 | //should work a bit like "make-button"(make-button BEG END &rest PROPERTIES) | ||
| 153 | // arg "type" and fwd should be keyword args eventually | ||
| 154 | //(make-xwidget 3 3 'button "oei" 31 31 nil) | ||
| 155 | //(xwidget-info (car xwidget-alist)) | ||
| 156 | struct xwidget* xw = allocate_xwidget(); | ||
| 157 | Lisp_Object val; | ||
| 158 | struct gcpro gcpro1; | ||
| 159 | GCPRO1(xw); | ||
| 160 | XSETSYMBOL(xw->type, type); | ||
| 161 | XSETSTRING(xw->title, title); | ||
| 162 | XSETBUFFER(xw->buffer, Fcurrent_buffer()); // conservatively gcpro xw since we call lisp | ||
| 163 | xw->height = XFASTINT(height); | ||
| 164 | xw->width = XFASTINT(width); | ||
| 165 | XSETPSEUDOVECTOR (val, xw, PVEC_OTHER); //?? dunno why i need this | ||
| 166 | Vxwidget_alist = Fcons ( val, Vxwidget_alist); | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | #ifdef HAVE_WEBKIT_OSR | ||
| 171 | /* DIY mvc. widget is rendered offscreen, | ||
| 172 | later bitmap copied to the views. | ||
| 173 | */ | ||
| 174 | if (EQ(xw->type, Qwebkit_osr) && !xw->widgetwindow_osr){ | ||
| 175 | BLOCK_INPUT; | ||
| 176 | xw->widgetwindow_osr = GTK_CONTAINER (gtk_offscreen_window_new ()); | ||
| 177 | gtk_window_resize( GTK_WINDOW(xw->widgetwindow_osr), xw->width, xw->height); | ||
| 178 | xw->widget_osr = webkit_web_view_new(); | ||
| 179 | |||
| 180 | gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width, xw->height); | ||
| 181 | gtk_container_add (xw->widgetwindow_osr, xw->widget_osr); | ||
| 182 | |||
| 183 | gtk_widget_show_all (GTK_WIDGET (xw->widgetwindow_osr)); | ||
| 184 | |||
| 185 | /* store some xwidget data in the gtk widgets for convenient retrieval in the event handlers. */ | ||
| 186 | g_object_set_data (G_OBJECT (xw->widget_osr), XG_XWIDGET, (gpointer) (xw)); | ||
| 187 | g_object_set_data (G_OBJECT (xw->widgetwindow_osr), XG_XWIDGET, (gpointer) (xw)); | ||
| 188 | g_signal_connect (G_OBJECT ( xw->widgetwindow_osr), "damage-event", G_CALLBACK (webkit_osr_damage_event_callback), NULL); | ||
| 189 | |||
| 190 | webkit_web_view_load_uri(WEBKIT_WEB_VIEW(xw->widget_osr), "http://www.fsf.org"); | ||
| 191 | UNBLOCK_INPUT; | ||
| 192 | |||
| 193 | } | ||
| 194 | #endif | ||
| 195 | |||
| 196 | |||
| 197 | UNGCPRO; | ||
| 198 | return val; | ||
| 199 | } | ||
| 126 | 200 | ||
| 127 | int | 201 | int |
| 128 | xwidget_hidden(struct xwidget_view *xv) | 202 | xwidget_hidden(struct xwidget_view *xv) |
| @@ -138,7 +212,7 @@ buttonclick_handler (GtkWidget * widget, gpointer data) | |||
| 138 | struct input_event event; | 212 | struct input_event event; |
| 139 | Lisp_Object frame; | 213 | Lisp_Object frame; |
| 140 | FRAME_PTR f = NULL;//(FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA); //TODO | 214 | FRAME_PTR f = NULL;//(FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA); //TODO |
| 141 | printf ("button clicked xw:%d id:%d\n", xw, xw->id); | 215 | printf ("button clicked xw:%d '%s'\n", xw, xw->title); |
| 142 | 216 | ||
| 143 | EVENT_INIT (event); | 217 | EVENT_INIT (event); |
| 144 | event.kind = XWIDGET_EVENT; | 218 | event.kind = XWIDGET_EVENT; |
| @@ -149,7 +223,7 @@ buttonclick_handler (GtkWidget * widget, gpointer data) | |||
| 149 | 223 | ||
| 150 | 224 | ||
| 151 | event.arg = Qnil; | 225 | event.arg = Qnil; |
| 152 | event.arg = Fcons (make_number (xw->id), event.arg); | 226 | //event.arg = Fcons (make_number (xw->id), event.arg); //TODO send the actual xwidget object now instead |
| 153 | event.arg = Fcons (intern ("buttonclick"), event.arg); | 227 | event.arg = Fcons (intern ("buttonclick"), event.arg); |
| 154 | 228 | ||
| 155 | kbd_buffer_store_event (&event); | 229 | kbd_buffer_store_event (&event); |
| @@ -159,7 +233,7 @@ buttonclick_handler (GtkWidget * widget, gpointer data) | |||
| 159 | 233 | ||
| 160 | 234 | ||
| 161 | static void | 235 | static void |
| 162 | send_xembed_ready_event (int xwid, int xembedid) | 236 | send_xembed_ready_event (struct xwidget* xw, int xembedid) |
| 163 | { | 237 | { |
| 164 | struct input_event event; | 238 | struct input_event event; |
| 165 | EVENT_INIT (event); | 239 | EVENT_INIT (event); |
| @@ -169,7 +243,7 @@ send_xembed_ready_event (int xwid, int xembedid) | |||
| 169 | event.arg = Qnil; | 243 | event.arg = Qnil; |
| 170 | event.arg = Fcons (make_number (xembedid), event.arg); | 244 | event.arg = Fcons (make_number (xembedid), event.arg); |
| 171 | event.arg = Fcons (intern ("xembed-ready"), event.arg); | 245 | event.arg = Fcons (intern ("xembed-ready"), event.arg); |
| 172 | event.arg = Fcons (make_number (xwid), event.arg); | 246 | // event.arg = Fcons (make_number (xwid), event.arg); //TODO |
| 173 | 247 | ||
| 174 | 248 | ||
| 175 | kbd_buffer_store_event (&event); | 249 | kbd_buffer_store_event (&event); |
| @@ -292,7 +366,7 @@ xwidget_osr_draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) | |||
| 292 | struct xwidget_view* xv = (struct xwidget_view*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET_VIEW); | 366 | struct xwidget_view* xv = (struct xwidget_view*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET_VIEW); |
| 293 | 367 | ||
| 294 | printf("xwidget_osr_draw_callback gtk3 xw.id:%d xw.type:%d window:%d vis:%d\n", | 368 | printf("xwidget_osr_draw_callback gtk3 xw.id:%d xw.type:%d window:%d vis:%d\n", |
| 295 | xw->id,xw->type, gtk_widget_get_window (widget), gtk_widget_get_visible (xw->widget_osr)); | 369 | xw,xw->type, gtk_widget_get_window (widget), gtk_widget_get_visible (xw->widget_osr)); |
| 296 | 370 | ||
| 297 | cairo_rectangle(cr, 0,0, xv->clip_right, xv->clip_bottom);//xw->width, xw->height); | 371 | cairo_rectangle(cr, 0,0, xv->clip_right, xv->clip_bottom);//xw->width, xw->height); |
| 298 | cairo_clip(cr); | 372 | cairo_clip(cr); |
| @@ -485,10 +559,10 @@ xwidget_init_view ( | |||
| 485 | //widgettype specific initialization only possible after realization | 559 | //widgettype specific initialization only possible after realization |
| 486 | if (EQ(xww->type, Qsocket)) { | 560 | if (EQ(xww->type, Qsocket)) { |
| 487 | printf ("xwid:%d socket id:%x %d\n", | 561 | printf ("xwid:%d socket id:%x %d\n", |
| 488 | xww->id, | 562 | xww, |
| 489 | gtk_socket_get_id (GTK_SOCKET (xv->widget)), | 563 | gtk_socket_get_id (GTK_SOCKET (xv->widget)), |
| 490 | gtk_socket_get_id (GTK_SOCKET (xv->widget))); | 564 | gtk_socket_get_id (GTK_SOCKET (xv->widget))); |
| 491 | send_xembed_ready_event (xww->id, | 565 | send_xembed_ready_event (xww, |
| 492 | gtk_socket_get_id (GTK_SOCKET (xv->widget))); | 566 | gtk_socket_get_id (GTK_SOCKET (xv->widget))); |
| 493 | //gtk_widget_realize(xw->widget); | 567 | //gtk_widget_realize(xw->widget); |
| 494 | } | 568 | } |
| @@ -507,7 +581,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s) | |||
| 507 | int box_line_hwidth = eabs (s->face->box_line_width); | 581 | int box_line_hwidth = eabs (s->face->box_line_width); |
| 508 | int box_line_vwidth = max (s->face->box_line_width, 0); | 582 | int box_line_vwidth = max (s->face->box_line_width, 0); |
| 509 | int height = s->height; | 583 | int height = s->height; |
| 510 | struct xwidget *xww = &xwidgets[s->xwidget_id]; | 584 | struct xwidget *xww = s->xwidget; |
| 511 | struct xwidget_view *xv = xwidget_view_lookup(xww, (s->w)); | 585 | struct xwidget_view *xv = xwidget_view_lookup(xww, (s->w)); |
| 512 | int clip_right; int clip_bottom; int clip_top; int clip_left; | 586 | int clip_right; int clip_bottom; int clip_top; int clip_left; |
| 513 | 587 | ||
| @@ -520,7 +594,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s) | |||
| 520 | We do it here in the display loop because there is no other time to know things like | 594 | We do it here in the display loop because there is no other time to know things like |
| 521 | window placement etc. | 595 | window placement etc. |
| 522 | */ | 596 | */ |
| 523 | printf ("xv init for xw %d\n", xww->id); | 597 | printf ("xv init for xw %d\n", xww); |
| 524 | xv = xwidget_init_view (xww, s, x, y); | 598 | xv = xwidget_init_view (xww, s, x, y); |
| 525 | } | 599 | } |
| 526 | 600 | ||
| @@ -571,46 +645,35 @@ x_draw_xwidget_glyph_string (struct glyph_string *s) | |||
| 571 | } | 645 | } |
| 572 | 646 | ||
| 573 | 647 | ||
| 574 | |||
| 575 | struct xwidget* xid2xw( Lisp_Object xwidget_id) | ||
| 576 | { | ||
| 577 | //TODO refactor this crap to something sane | ||
| 578 | struct xwidget *xw; | ||
| 579 | int xid; | ||
| 580 | |||
| 581 | CHECK_NUMBER (xwidget_id); | ||
| 582 | xid = XFASTINT (xwidget_id); | ||
| 583 | xw = &xwidgets[xid]; | ||
| 584 | return xw; | ||
| 585 | } | ||
| 586 | |||
| 587 | |||
| 588 | #ifdef HAVE_WEBKIT_OSR | 648 | #ifdef HAVE_WEBKIT_OSR |
| 589 | DEFUN ("xwidget-webkit-goto-uri", Fxwidget_webkit_goto_uri, Sxwidget_webkit_goto_uri, 2, 2, 0, | 649 | DEFUN ("xwidget-webkit-goto-uri", Fxwidget_webkit_goto_uri, Sxwidget_webkit_goto_uri, 2, 2, 0, |
| 590 | doc: /* webkit goto uri.*/ | 650 | doc: /* webkit goto uri.*/ |
| 591 | ) | 651 | ) |
| 592 | (Lisp_Object xwidget_id, Lisp_Object uri) | 652 | (Lisp_Object xwidget, Lisp_Object uri) |
| 593 | { | 653 | { |
| 594 | webkit_web_view_load_uri ( WEBKIT_WEB_VIEW(xid2xw(xwidget_id)->widget_osr), SDATA(uri)); | 654 | struct xwidget* xw = XXWIDGET(xwidget); |
| 655 | webkit_web_view_load_uri ( WEBKIT_WEB_VIEW(xw->widget_osr), SDATA(uri)); | ||
| 595 | return Qnil; | 656 | return Qnil; |
| 596 | } | 657 | } |
| 597 | 658 | ||
| 598 | DEFUN ("xwidget-webkit-execute-script", Fxwidget_webkit_execute_script, Sxwidget_webkit_execute_script, 2, 2, 0, | 659 | DEFUN ("xwidget-webkit-execute-script", Fxwidget_webkit_execute_script, Sxwidget_webkit_execute_script, 2, 2, 0, |
| 599 | doc: /* webkit exec js.*/ | 660 | doc: /* webkit exec js.*/ |
| 600 | ) | 661 | ) |
| 601 | (Lisp_Object xwidget_id, Lisp_Object script) | 662 | (Lisp_Object xwidget, Lisp_Object script) |
| 602 | { | 663 | { |
| 603 | webkit_web_view_execute_script( WEBKIT_WEB_VIEW(xid2xw(xwidget_id)->widget_osr), SDATA(script)); | 664 | struct xwidget* xw = XXWIDGET(xwidget); |
| 665 | webkit_web_view_execute_script( WEBKIT_WEB_VIEW(xw->widget_osr), SDATA(script)); | ||
| 604 | return Qnil; | 666 | return Qnil; |
| 605 | } | 667 | } |
| 606 | 668 | ||
| 607 | DEFUN ("xwidget-webkit-get-title", Fxwidget_webkit_get_title, Sxwidget_webkit_get_title, 1, 1, 0, | 669 | DEFUN ("xwidget-webkit-get-title", Fxwidget_webkit_get_title, Sxwidget_webkit_get_title, 1, 1, 0, |
| 608 | doc: /* webkit get title. can be used to work around exec method lacks return val*/ | 670 | doc: /* webkit get title. can be used to work around exec method lacks return val*/ |
| 609 | ) | 671 | ) |
| 610 | (Lisp_Object xwidget_id) | 672 | (Lisp_Object xwidget) |
| 611 | { | 673 | { |
| 612 | //TODO support multibyte strings | 674 | //TODO support multibyte strings |
| 613 | const gchar* str=webkit_web_view_get_title( WEBKIT_WEB_VIEW(xid2xw(xwidget_id)->widget_osr)); | 675 | struct xwidget* xw = XXWIDGET(xwidget); |
| 676 | const gchar* str=webkit_web_view_get_title( WEBKIT_WEB_VIEW(xw->widget_osr)); | ||
| 614 | return make_string_from_bytes(str, wcslen((const wchar_t *)str), strlen(str)); | 677 | return make_string_from_bytes(str, wcslen((const wchar_t *)str), strlen(str)); |
| 615 | } | 678 | } |
| 616 | 679 | ||
| @@ -620,33 +683,13 @@ DEFUN ("xwidget-webkit-get-title", Fxwidget_webkit_get_title, Sxwidget_webkit_g | |||
| 620 | 683 | ||
| 621 | 684 | ||
| 622 | 685 | ||
| 623 | DEFUN ("xwidget-embed-steal-window", Fxwidget_embed_steal_window, Sxwidget_embed_steal_window, 2, 2, 0, | ||
| 624 | doc: /* Tell existing embed xwidget to steal other window id. This is based on a deprecated method in GTK and doesnt work too well.*/ | ||
| 625 | ) | ||
| 626 | (Lisp_Object xwidget_id, Lisp_Object window_id) | ||
| 627 | { | ||
| 628 | int iwindow_id; | ||
| 629 | struct xwidget* xw = xid2xw(xwidget_id); | ||
| 630 | |||
| 631 | CHECK_NUMBER (window_id); | ||
| 632 | iwindow_id = XFASTINT (window_id); | ||
| 633 | |||
| 634 | // gtk_socket_steal(GTK_SOCKET(xw->widget),iwindow_id); | ||
| 635 | //try adding proper gtk plugs instead, i never once had "steal" work | ||
| 636 | ///////// gtk_socket_add_id (GTK_SOCKET (xw->widget), iwindow_id); /////TODO MVC | ||
| 637 | //add_id annoyingly odesnt work either. the only working option | ||
| 638 | //seems to be clients that plug into the sockets, and so far only emacs and mplayer | ||
| 639 | //oenvrml | ||
| 640 | return Qnil; | ||
| 641 | } | ||
| 642 | |||
| 643 | 686 | ||
| 644 | 687 | ||
| 645 | DEFUN ("xwidget-resize-internal", Fxwidget_resize_internal, Sxwidget_resize_internal, 3, 3, 0, doc: | 688 | DEFUN ("xwidget-resize-internal", Fxwidget_resize_internal, Sxwidget_resize_internal, 3, 3, 0, doc: |
| 646 | /* resize xwidgets internal use only, because the lisp specs need to be updated also*/) | 689 | /* resize xwidgets internal use only, because the lisp specs need to be updated also*/) |
| 647 | (Lisp_Object xwidget_id, Lisp_Object new_width, Lisp_Object new_height) | 690 | (Lisp_Object xwidget, Lisp_Object new_width, Lisp_Object new_height) |
| 648 | { | 691 | { |
| 649 | struct xwidget *xw; | 692 | struct xwidget* xw = XXWIDGET(xwidget); |
| 650 | struct xwidget_view *xv; | 693 | struct xwidget_view *xv; |
| 651 | int w, h; | 694 | int w, h; |
| 652 | 695 | ||
| @@ -654,9 +697,9 @@ DEFUN ("xwidget-resize-internal", Fxwidget_resize_internal, Sxwidget_resize_inte | |||
| 654 | CHECK_NUMBER (new_height); | 697 | CHECK_NUMBER (new_height); |
| 655 | w = XFASTINT (new_width); | 698 | w = XFASTINT (new_width); |
| 656 | h = XFASTINT (new_height); | 699 | h = XFASTINT (new_height); |
| 657 | xw = xid2xw(xwidget_id); | 700 | |
| 658 | 701 | ||
| 659 | printf("resize xwidget %d (%d,%d)->(%d,%d)",xw->id,xw->width,xw->height,w,h); | 702 | printf("resize xwidget %d (%d,%d)->(%d,%d)",xw, xw->width,xw->height,w,h); |
| 660 | xw->width=w; | 703 | xw->width=w; |
| 661 | xw->height=h; | 704 | xw->height=h; |
| 662 | for (int i = 0; i < MAX_XWIDGETS; i++) //TODO MVC refactor lazy linear search | 705 | for (int i = 0; i < MAX_XWIDGETS; i++) //TODO MVC refactor lazy linear search |
| @@ -673,26 +716,28 @@ DEFUN ("xwidget-resize-internal", Fxwidget_resize_internal, Sxwidget_resize_inte | |||
| 673 | 716 | ||
| 674 | 717 | ||
| 675 | 718 | ||
| 719 | |||
| 676 | DEFUN("xwidget-info", Fxwidget_info , Sxwidget_info, 1,1,0, doc: /* get xwidget props */) | 720 | DEFUN("xwidget-info", Fxwidget_info , Sxwidget_info, 1,1,0, doc: /* get xwidget props */) |
| 677 | (Lisp_Object xwidget_id) | 721 | (Lisp_Object xwidget) |
| 678 | { | 722 | { |
| 679 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 680 | Lisp_Object info; | 723 | Lisp_Object info; |
| 724 | struct xwidget* xw = XXWIDGET(xwidget); | ||
| 681 | 725 | ||
| 682 | info = Fmake_vector (make_number (4), Qnil); | 726 | info = Fmake_vector (make_number (4), Qnil); |
| 683 | XVECTOR (info)->contents[0] = make_number(xw->id); | 727 | XSETSYMBOL (XVECTOR (info)->contents[0], xw->type); |
| 684 | XVECTOR (info)->contents[1] = xw->type; | 728 | XSETSTRING (XVECTOR (info)->contents[1], xw->title); |
| 685 | XVECTOR (info)->contents[2] = make_number(xw->width); | 729 | XSETINT (XVECTOR (info)->contents[2], xw->width); |
| 686 | XVECTOR (info)->contents[3] = make_number(xw->height); | 730 | XSETINT (XVECTOR (info)->contents[3], xw->height); |
| 687 | 731 | ||
| 688 | 732 | ||
| 689 | return info; | 733 | return info; |
| 690 | } | 734 | } |
| 691 | 735 | ||
| 736 | |||
| 692 | DEFUN("xwidget-view-info", Fxwidget_view_info , Sxwidget_view_info, 2,2,0, doc: /* get xwidget view props */) | 737 | DEFUN("xwidget-view-info", Fxwidget_view_info , Sxwidget_view_info, 2,2,0, doc: /* get xwidget view props */) |
| 693 | (Lisp_Object xwidget_id, Lisp_Object window) | 738 | (Lisp_Object xwidget, Lisp_Object window) |
| 694 | { | 739 | { |
| 695 | struct xwidget *xw = xid2xw(xwidget_id); | 740 | struct xwidget* xw = XXWIDGET(xwidget); |
| 696 | struct xwidget_view* xv = xwidget_view_lookup(xw, XWINDOW(window)); | 741 | struct xwidget_view* xv = xwidget_view_lookup(xw, XWINDOW(window)); |
| 697 | 742 | ||
| 698 | Lisp_Object info; | 743 | Lisp_Object info; |
| @@ -708,139 +753,17 @@ DEFUN("xwidget-view-info", Fxwidget_view_info , Sxwidget_view_info, 2,2,0, doc: | |||
| 708 | return info; | 753 | return info; |
| 709 | } | 754 | } |
| 710 | 755 | ||
| 711 | |||
| 712 | |||
| 713 | //xterm.c listens to xwidget_owns_kbd and tries to not eat events when its set | ||
| 714 | int xwidget_owns_kbd = 0; | ||
| 715 | DEFUN ("xwidget-set-keyboard-grab", Fxwidget_set_keyboard_grab, Sxwidget_set_keyboard_grab, 2, 2, 0, doc: /* set unset kbd grab for xwidget. */ | ||
| 716 | ) | ||
| 717 | (Lisp_Object xwidget_id, Lisp_Object kbd_grab) | ||
| 718 | { | ||
| 719 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 720 | int xid, kbd_flag; | ||
| 721 | |||
| 722 | CHECK_NUMBER (kbd_grab); | ||
| 723 | kbd_flag = XFASTINT (kbd_grab); | ||
| 724 | |||
| 725 | |||
| 726 | |||
| 727 | printf ("kbd grab: %d %d\n", xid, kbd_flag); | ||
| 728 | if (kbd_flag) | ||
| 729 | { | ||
| 730 | //int rv=gtk_widget_activate(xw->widget); //ok, but how deactivate? | ||
| 731 | //printf("activation:%d\n",rv); | ||
| 732 | // gtk_window_present(GTK_WINDOW(xw->widget)); | ||
| 733 | //gtk_widget_grab_focus(xw->widget); | ||
| 734 | // gtk_socket_windowing_update_active (xw->widget,1); | ||
| 735 | // GDK_WINDOW_XWINDOW (GTK_WIDGET (socket)->window) | ||
| 736 | //FRAME_X_OUTPUT (f)->widget | ||
| 737 | // gdk_keyboard_grab(xw->widget,TRUE,GDK_CURRENT_TIME); | ||
| 738 | |||
| 739 | /* GtkWidget *parent = gtk_widget_get_parent (xw->widget); */ | ||
| 740 | /* GtkWidget *lastparent; */ | ||
| 741 | /* for (lastparent = parent; parent = gtk_widget_get_parent (parent); */ | ||
| 742 | /* parent == NULL); */ | ||
| 743 | |||
| 744 | /* gtk_container_set_focus_child (GTK_CONTAINER (lastparent), xw->widget); */ | ||
| 745 | |||
| 746 | ////gtk_container_set_focus_child (GTK_CONTAINER (xw->widgetwindow), xw->widget); //TODO MVC | ||
| 747 | |||
| 748 | xwidget_owns_kbd = TRUE; | ||
| 749 | } | ||
| 750 | else | ||
| 751 | { | ||
| 752 | xwidget_owns_kbd = FALSE; | ||
| 753 | } | ||
| 754 | /* | ||
| 755 | gdk_keyboard_grab(xw->widget,TRUE,GDK_CURRENT_TIME); | ||
| 756 | else | ||
| 757 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); | ||
| 758 | */ | ||
| 759 | return Qnil; | ||
| 760 | } | ||
| 761 | |||
| 762 | |||
| 763 | //lowlevel fn mostly cloned from xembed_send_message() | ||
| 764 | void | ||
| 765 | xwidget_key_send_message (struct frame *f, | ||
| 766 | Window destination_window, | ||
| 767 | int keycode, int keypress, int modifiers) | ||
| 768 | { | ||
| 769 | |||
| 770 | XKeyEvent event; | ||
| 771 | //segfaults: | ||
| 772 | /* xwidget_key_send_message (f=0x0, destination_window=0, keycode=65, keypress=1, */ | ||
| 773 | /* modifiers=0) at xwidget.c:332 */ | ||
| 774 | /* 332 event.display = FRAME_X_DISPLAY (f); */ | ||
| 775 | |||
| 776 | event.display = FRAME_X_DISPLAY (f); | ||
| 777 | event.window = destination_window; | ||
| 778 | event.root = FRAME_X_WINDOW (f); | ||
| 779 | event.subwindow = None; | ||
| 780 | event.time = CurrentTime; | ||
| 781 | event.x = 1; | ||
| 782 | event.y = 1; | ||
| 783 | event.x_root = 1; | ||
| 784 | event.y_root = 1; | ||
| 785 | event.same_screen = TRUE; | ||
| 786 | |||
| 787 | event.type = keypress ? KeyPress : KeyRelease; | ||
| 788 | event.keycode = keycode; | ||
| 789 | event.state = modifiers; | ||
| 790 | |||
| 791 | XSendEvent (event.display, event.window, TRUE, KeyPressMask, | ||
| 792 | (XEvent *) & event); | ||
| 793 | } | ||
| 794 | |||
| 795 | //using "accessible" interfaces seems expensive | ||
| 796 | //pkg-config --cflags cspi-1.0 | ||
| 797 | //#include <at-spi-1.0/cspi/spi.h> | ||
| 798 | |||
| 799 | DEFUN ("xwidget-send-keyboard-event", Fxwidget_send_keyboard_event, Sxwidget_send_keyboard_event, 2, 2, 0, doc:/* synthesize a kbd event for a xwidget. */ | ||
| 800 | ) | ||
| 801 | (Lisp_Object xwidget_id, Lisp_Object keydescriptor) | ||
| 802 | { | ||
| 803 | int keyval; | ||
| 804 | char *keystring = ""; | ||
| 805 | FRAME_PTR f; | ||
| 806 | struct xwidget *xw = xid2xw(xwidget_id); | ||
| 807 | GdkWindow *window; | ||
| 808 | XID xid; | ||
| 809 | |||
| 810 | /* TODO MVC | ||
| 811 | f = (FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA); | ||
| 812 | |||
| 813 | //GdkWindow* window=gtk_widget_get_window(xw->widget); //event winds up in emacs | ||
| 814 | |||
| 815 | //TODO assert xw is a gtk_socket or THIS WILL FAIL GLORIOUSLY | ||
| 816 | window = gtk_socket_get_plug_window (GTK_SOCKET (xw->widget)); | ||
| 817 | //the event gets eaten somewhere. | ||
| 818 | //i suspect you just cant send an event to a child window and not have emacs eat it. | ||
| 819 | //but if this were true the event should pop to emacs right? | ||
| 820 | |||
| 821 | |||
| 822 | xid = gdk_x11_drawable_get_xid (window); | ||
| 823 | |||
| 824 | printf ("xwidget-send-keyboard-event %d %d\n", window, xid); | ||
| 825 | |||
| 826 | xwidget_key_send_message (f, xid, 38, 1, 0); //38 is 'a' HACK for now | ||
| 827 | xwidget_key_send_message (f, xid, 38, 0, 0); | ||
| 828 | */ | ||
| 829 | return Qnil; | ||
| 830 | } | ||
| 831 | |||
| 832 | void | 756 | void |
| 833 | syms_of_xwidget (void) | 757 | syms_of_xwidget (void) |
| 834 | { | 758 | { |
| 835 | int i; | 759 | int i; |
| 836 | 760 | ||
| 837 | defsubr (&Sxwidget_set_keyboard_grab); | 761 | defsubr (&Smake_xwidget); |
| 838 | defsubr (&Sxwidget_send_keyboard_event); | 762 | |
| 839 | defsubr (&Sxwidget_embed_steal_window); | ||
| 840 | defsubr (&Sxwidget_info); | 763 | defsubr (&Sxwidget_info); |
| 841 | defsubr (&Sxwidget_view_info); | 764 | defsubr (&Sxwidget_view_info); |
| 842 | defsubr (&Sxwidget_resize_internal); | 765 | defsubr (&Sxwidget_resize_internal); |
| 843 | defsubr (&Sxwidget_embed_steal_window); | 766 | |
| 844 | 767 | ||
| 845 | defsubr (&Sxwidget_webkit_goto_uri); | 768 | defsubr (&Sxwidget_webkit_goto_uri); |
| 846 | defsubr (&Sxwidget_webkit_execute_script); | 769 | defsubr (&Sxwidget_webkit_execute_script); |
| @@ -848,7 +771,7 @@ syms_of_xwidget (void) | |||
| 848 | 771 | ||
| 849 | DEFSYM (Qxwidget ,"xwidget"); | 772 | DEFSYM (Qxwidget ,"xwidget"); |
| 850 | 773 | ||
| 851 | DEFSYM (Qxwidget_id ,":xwidget-id"); | 774 | DEFSYM (Qcxwidget ,":xwidget"); |
| 852 | DEFSYM (Qtitle ,":title"); | 775 | DEFSYM (Qtitle ,":title"); |
| 853 | 776 | ||
| 854 | DEFSYM (Qbutton, "button"); | 777 | DEFSYM (Qbutton, "button"); |
| @@ -859,10 +782,15 @@ syms_of_xwidget (void) | |||
| 859 | DEFSYM (Qwebkit_osr ,"webkit-osr"); | 782 | DEFSYM (Qwebkit_osr ,"webkit-osr"); |
| 860 | DEFSYM (QCplist, ":plist"); | 783 | DEFSYM (QCplist, ":plist"); |
| 861 | 784 | ||
| 785 | DEFVAR_LISP ("xwidget-alist", Vxwidget_alist, doc: /*xwidgets list*/); | ||
| 786 | Vxwidget_alist = Qnil; | ||
| 787 | DEFVAR_LISP ("xwidget-view-alist", Vxwidget_view_alist, doc: /*xwidget views list*/); | ||
| 788 | Vxwidget_alist = Qnil; | ||
| 789 | |||
| 862 | Fprovide (intern ("xwidget-internal"), Qnil); | 790 | Fprovide (intern ("xwidget-internal"), Qnil); |
| 863 | 791 | ||
| 864 | for (i = 0; i < MAX_XWIDGETS; i++) | 792 | // for (i = 0; i < MAX_XWIDGETS; i++) |
| 865 | xwidgets[i].initialized = 0; | 793 | //xwidgets[i].initialized = 0; |
| 866 | } | 794 | } |
| 867 | 795 | ||
| 868 | 796 | ||
| @@ -931,22 +859,6 @@ xwidget_spec_value ( Lisp_Object spec, Lisp_Object key, | |||
| 931 | return Qnil; | 859 | return Qnil; |
| 932 | } | 860 | } |
| 933 | 861 | ||
| 934 | void | ||
| 935 | assert_valid_xwidget_id (int id, char *str) | ||
| 936 | { | ||
| 937 | if (id < 0 || id > MAX_XWIDGETS) | ||
| 938 | { | ||
| 939 | printf ("broken xwidgetid:%d %s\n", id, str); | ||
| 940 | abort (); | ||
| 941 | } | ||
| 942 | } | ||
| 943 | |||
| 944 | struct xwidget * | ||
| 945 | xwidget_from_id (int id) | ||
| 946 | { | ||
| 947 | assert_valid_xwidget_id (id, "xwidget_from_id"); | ||
| 948 | return &xwidgets[id]; | ||
| 949 | } | ||
| 950 | 862 | ||
| 951 | void xwidget_view_delete_all_in_window( struct window *w ) | 863 | void xwidget_view_delete_all_in_window( struct window *w ) |
| 952 | { | 864 | { |
| @@ -980,7 +892,7 @@ void gtk_window_get_position (GtkWindow *window, | |||
| 980 | 892 | ||
| 981 | 893 | ||
| 982 | 894 | ||
| 983 | int | 895 | struct xwidget* |
| 984 | lookup_xwidget (Lisp_Object spec) | 896 | lookup_xwidget (Lisp_Object spec) |
| 985 | { | 897 | { |
| 986 | /* When a xwidget lisp spec is found initialize the C struct that is used in the C code. | 898 | /* When a xwidget lisp spec is found initialize the C struct that is used in the C code. |
| @@ -992,57 +904,28 @@ lookup_xwidget (Lisp_Object spec) | |||
| 992 | */ | 904 | */ |
| 993 | int found = 0, found1 = 0, found2 = 0; | 905 | int found = 0, found1 = 0, found2 = 0; |
| 994 | Lisp_Object value; | 906 | Lisp_Object value; |
| 995 | int id; | ||
| 996 | struct xwidget *xw; | 907 | struct xwidget *xw; |
| 997 | 908 | ||
| 998 | value = xwidget_spec_value (spec, Qxwidget_id, &found1); | 909 | value = xwidget_spec_value (spec, Qcxwidget, &found1); |
| 999 | id = INTEGERP (value) ? XFASTINT (value) : 0; //TODO id 0 by default, but id must be unique so this is dumb | 910 | xw = XXWIDGET(value); |
| 1000 | 911 | ||
| 1001 | xw = &xwidgets[id]; | 912 | /* value = xwidget_spec_value (spec, QCtype, &found); */ |
| 1002 | xw->id=id; | 913 | /* xw->type = SYMBOLP (value) ? value : Qbutton; //default to button */ |
| 1003 | value = xwidget_spec_value (spec, QCtype, &found); | 914 | /* value = xwidget_spec_value (spec, Qtitle, &found2); */ |
| 1004 | xw->type = SYMBOLP (value) ? value : Qbutton; //default to button | 915 | /* xw->title = STRINGP (value) ? (char *) SDATA (value) : "?"; //funky cast FIXME TODO */ |
| 1005 | value = xwidget_spec_value (spec, Qtitle, &found2); | ||
| 1006 | xw->title = STRINGP (value) ? (char *) SDATA (value) : "?"; //funky cast FIXME TODO | ||
| 1007 | 916 | ||
| 1008 | value = xwidget_spec_value (spec, QCheight, NULL); | 917 | /* value = xwidget_spec_value (spec, QCheight, NULL); */ |
| 1009 | xw->height = INTEGERP (value) ? XFASTINT (value) : 50; | 918 | /* xw->height = INTEGERP (value) ? XFASTINT (value) : 50; */ |
| 1010 | value = xwidget_spec_value (spec, QCwidth, NULL); | 919 | /* value = xwidget_spec_value (spec, QCwidth, NULL); */ |
| 1011 | xw->width = INTEGERP (value) ? XFASTINT (value) : 50; | 920 | /* xw->width = INTEGERP (value) ? XFASTINT (value) : 50; */ |
| 1012 | 921 | ||
| 1013 | value = xwidget_spec_value (spec, QCplist, NULL); | 922 | /* value = xwidget_spec_value (spec, QCplist, NULL); */ |
| 1014 | xw->plist = value; | 923 | /* xw->plist = value; */ |
| 1015 | printf ("xwidget_id:%d type:%d found:%d %d %d title:%s (%d,%d)\n", id, | 924 | printf ("xwidget_id:%d type:%d found:%d %d %d title:%s (%d,%d)\n", xw, |
| 1016 | xw->type, found, found1, found2, xw->title, xw->height, xw->width); | 925 | xw->type, found, found1, found2, xw->title, xw->height, xw->width); |
| 1017 | 926 | ||
| 1018 | assert_valid_xwidget_id (id, "lookup_xwidget"); | 927 | //assert_valid_xwidget_id (id, "lookup_xwidget"); |
| 1019 | 928 | return xw; | |
| 1020 | #ifdef HAVE_WEBKIT_OSR | ||
| 1021 | /* DIY mvc. widget is rendered offscreen, | ||
| 1022 | later bitmap copied to the views. | ||
| 1023 | */ | ||
| 1024 | if (EQ(xw->type, Qwebkit_osr) && !xw->widgetwindow_osr){ | ||
| 1025 | BLOCK_INPUT; | ||
| 1026 | xw->widgetwindow_osr = GTK_CONTAINER (gtk_offscreen_window_new ()); | ||
| 1027 | gtk_window_resize( GTK_WINDOW(xw->widgetwindow_osr), xw->width, xw->height); | ||
| 1028 | xw->widget_osr = webkit_web_view_new(); | ||
| 1029 | |||
| 1030 | gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width, xw->height); | ||
| 1031 | gtk_container_add (xw->widgetwindow_osr, xw->widget_osr); | ||
| 1032 | |||
| 1033 | gtk_widget_show_all (GTK_WIDGET (xw->widgetwindow_osr)); | ||
| 1034 | |||
| 1035 | /* store some xwidget data in the gtk widgets for convenient retrieval in the event handlers. */ | ||
| 1036 | g_object_set_data (G_OBJECT (xw->widget_osr), XG_XWIDGET, (gpointer) (xw)); | ||
| 1037 | g_object_set_data (G_OBJECT (xw->widgetwindow_osr), XG_XWIDGET, (gpointer) (xw)); | ||
| 1038 | g_signal_connect (G_OBJECT ( xw->widgetwindow_osr), "damage-event", G_CALLBACK (webkit_osr_damage_event_callback), NULL); | ||
| 1039 | |||
| 1040 | webkit_web_view_load_uri(WEBKIT_WEB_VIEW(xw->widget_osr), "http://www.fsf.org"); | ||
| 1041 | UNBLOCK_INPUT; | ||
| 1042 | |||
| 1043 | } | ||
| 1044 | #endif | ||
| 1045 | return id; | ||
| 1046 | } | 929 | } |
| 1047 | 930 | ||
| 1048 | /*set up detection of touched xwidget*/ | 931 | /*set up detection of touched xwidget*/ |
| @@ -1101,27 +984,12 @@ xwidget_end_redisplay (struct glyph_matrix *matrix) | |||
| 1101 | { | 984 | { |
| 1102 | if (glyph->type == XWIDGET_GLYPH) | 985 | if (glyph->type == XWIDGET_GLYPH) |
| 1103 | { | 986 | { |
| 1104 | //printf("(%d)",glyph->u.xwidget_id); | ||
| 1105 | //here the id sometimes sucks, so maybe the desired glyph matrix isnt ready here? | ||
| 1106 | //also, it appears the desired matrix is not the entire window, but only the changed part. wtf? | ||
| 1107 | int id = glyph->u.xwidget_id; | ||
| 1108 | if (id < 0 || id > MAX_XWIDGETS) | ||
| 1109 | { | ||
| 1110 | printf | ||
| 1111 | ("glyph matrix contains crap, abort xwidget handling and wait for better times\n "); | ||
| 1112 | //dump_glyph_matrix(matrix, 2); | ||
| 1113 | return; | ||
| 1114 | } | ||
| 1115 | else | ||
| 1116 | { | ||
| 1117 | // printf("row %d not enabled\n", i); | ||
| 1118 | } | ||
| 1119 | /* | 987 | /* |
| 1120 | the only call to xwidget_end_redisplay is in dispnew and looks like: | 988 | the only call to xwidget_end_redisplay is in dispnew and looks like: |
| 1121 | if ((XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME()))) == (w)) | 989 | if ((XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME()))) == (w)) |
| 1122 | xwidget_end_redisplay(w->current_matrix); | 990 | xwidget_end_redisplay(w->current_matrix); |
| 1123 | */ | 991 | */ |
| 1124 | xwidget_touch (xwidget_view_lookup(&xwidgets[glyph->u.xwidget_id], | 992 | xwidget_touch (xwidget_view_lookup(glyph->u.xwidget, |
| 1125 | (XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME()))))); | 993 | (XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME()))))); |
| 1126 | } | 994 | } |
| 1127 | } | 995 | } |
diff --git a/src/xwidget.h b/src/xwidget.h index b906b71c10b..181d2232518 100644 --- a/src/xwidget.h +++ b/src/xwidget.h | |||
| @@ -2,8 +2,7 @@ void x_draw_xwidget_glyph_string (struct glyph_string *s); | |||
| 2 | void syms_of_xwidget (); | 2 | void syms_of_xwidget (); |
| 3 | 3 | ||
| 4 | extern Lisp_Object Qxwidget; | 4 | extern Lisp_Object Qxwidget; |
| 5 | /* Test for xwidget (xwidget . spec) (car must be the symbol xwidget)*/ | 5 | |
| 6 | #define XWIDGETP(x) (CONSP (x) && EQ (XCAR (x), Qxwidget)) | ||
| 7 | 6 | ||
| 8 | int valid_xwidget_p (Lisp_Object object) ; | 7 | int valid_xwidget_p (Lisp_Object object) ; |
| 9 | 8 | ||
| @@ -12,33 +11,48 @@ int valid_xwidget_p (Lisp_Object object) ; | |||
| 12 | 11 | ||
| 13 | /* | 12 | /* |
| 14 | each xwidget instance/model is described by this struct. | 13 | each xwidget instance/model is described by this struct. |
| 14 | |||
| 15 | lisp pseudovector. | ||
| 16 | |||
| 17 | |||
| 15 | */ | 18 | */ |
| 16 | struct xwidget{ | 19 | struct xwidget{ |
| 20 | struct vectorlike_header header; | ||
| 17 | Lisp_Object plist;//auxilliary data | 21 | Lisp_Object plist;//auxilliary data |
| 18 | Lisp_Object type;//the widget type | 22 | Lisp_Object type;//the widget type |
| 19 | 23 | Lisp_Object buffer; //buffer where xwidget lives | |
| 20 | int id; // id is stored inside the struct which is conveniont in some cases | 24 | |
| 21 | char* title;//a title that is used for button labels for instance | 25 | //here ends the lisp part. |
| 22 | 26 | //"height" is the marker field | |
| 23 | |||
| 24 | int height; | 27 | int height; |
| 25 | int width; | 28 | int width; |
| 26 | int initialized; | ||
| 27 | |||
| 28 | 29 | ||
| 29 | //for offscreen widgets, unused if not osr | 30 | //for offscreen widgets, unused if not osr |
| 30 | GtkWidget* widget_osr; | 31 | GtkWidget* widget_osr; |
| 31 | GtkContainer* widgetwindow_osr; | 32 | GtkContainer* widgetwindow_osr; |
| 32 | 33 | ||
| 34 | //TODO these are WIP | ||
| 35 | char* title;//a title that is used for button labels for instance | ||
| 36 | |||
| 37 | |||
| 33 | }; | 38 | }; |
| 34 | 39 | ||
| 35 | 40 | ||
| 36 | //struct for each xwidget view | 41 | //struct for each xwidget view |
| 37 | struct xwidget_view{ | 42 | struct xwidget_view{ |
| 38 | struct xwidget* model; | 43 | struct vectorlike_header header; |
| 44 | struct xwidget* model; //TODO should be lisp | ||
| 45 | |||
| 46 | |||
| 47 | //here ends the lisp part. | ||
| 48 | //"redisplayed" is the marker field | ||
| 49 | int redisplayed; //if touched by redisplay | ||
| 50 | |||
| 39 | 51 | ||
| 52 | struct window *w; //TODO should be lisp | ||
| 53 | |||
| 40 | int hidden;//if the "live" instance isnt drawn | 54 | int hidden;//if the "live" instance isnt drawn |
| 41 | int redisplayed; //if touched by redisplay | 55 | |
| 42 | int initialized; | 56 | int initialized; |
| 43 | 57 | ||
| 44 | GtkWidget* widget; | 58 | GtkWidget* widget; |
| @@ -46,13 +60,15 @@ struct xwidget_view{ | |||
| 46 | GtkContainer* emacswindow; | 60 | GtkContainer* emacswindow; |
| 47 | int x; int y; | 61 | int x; int y; |
| 48 | int clip_right; int clip_bottom; int clip_top; int clip_left; | 62 | int clip_right; int clip_bottom; int clip_top; int clip_left; |
| 49 | struct window *w; | 63 | |
| 50 | 64 | ||
| 51 | long handler_id; | 65 | long handler_id; |
| 52 | }; | 66 | }; |
| 53 | 67 | ||
| 54 | 68 | ||
| 55 | 69 | /* Test for xwidget (xwidget . spec) (car must be the symbol xwidget)*/ | |
| 70 | #define XWIDGETP(x) (CONSP (x) && EQ (XCAR (x), Qxwidget)) | ||
| 71 | #define XXWIDGET(a) (eassert (XWIDGETP(a)),(struct xwidget *) XPNTR(a)) | ||
| 56 | 72 | ||
| 57 | 73 | ||
| 58 | struct xwidget_type | 74 | struct xwidget_type |
| @@ -72,16 +88,16 @@ static struct xwidget_type *lookup_xwidget_type (Lisp_Object symbol); | |||
| 72 | 88 | ||
| 73 | struct xwidget* xwidget_from_id(int id); | 89 | struct xwidget* xwidget_from_id(int id); |
| 74 | 90 | ||
| 75 | extern int xwidget_owns_kbd; | 91 | //extern int xwidget_owns_kbd; |
| 76 | 92 | ||
| 77 | void xwidget_start_redisplay(); | 93 | void xwidget_start_redisplay(); |
| 78 | void xwidget_end_redisplay(struct glyph_matrix* matrix); | 94 | void xwidget_end_redisplay(struct glyph_matrix* matrix); |
| 79 | 95 | ||
| 80 | void xwidget_touch (struct xwidget_view *xw); | 96 | void xwidget_touch (struct xwidget_view *xw); |
| 81 | 97 | ||
| 82 | void assert_valid_xwidget_id(int id,char *str); | 98 | //void assert_valid_xwidget_id(int id,char *str); |
| 83 | 99 | ||
| 84 | int lookup_xwidget (Lisp_Object spec); | 100 | struct xwidget* lookup_xwidget (Lisp_Object spec); |
| 85 | #define XG_XWIDGET "emacs_xwidget" | 101 | #define XG_XWIDGET "emacs_xwidget" |
| 86 | #define XG_XWIDGET_VIEW "emacs_xwidget_view" | 102 | #define XG_XWIDGET_VIEW "emacs_xwidget_view" |
| 87 | void xwidget_view_delete_all_in_window( struct window *w ); | 103 | void xwidget_view_delete_all_in_window( struct window *w ); |