From: Po Lu Date: Sat, 6 Nov 2021 03:28:40 +0000 (+0800) Subject: Add support for cursors in xwidget views X-Git-Tag: emacs-29.0.90~3671^2~131 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1cc19d0437a712a1589c0adaaa65d7c12decd8c1;p=emacs.git Add support for cursors in xwidget views * src/xwidget.c (mouse_target_changed): New function. (Fmake_xwidget): Attach mouse target changed signal. (cursor_for_hit, define_cursors, mouse_target_changed): New functions. (xwidget_init_view): Set default cursor to nontext cursor. (x_draw_xwidget_glyph_string): Define cursor. * src/xwidget.h (struct xwidget_view): Add cursor field. --- diff --git a/src/xwidget.c b/src/xwidget.c index 5f0dd2644a1..1f93cd39515 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -94,6 +94,8 @@ struct widget_search_data }; static void find_widget (GtkWidget *t, struct widget_search_data *); +static void mouse_target_changed (WebKitWebView *, WebKitHitTestResult *, guint, + gpointer); #endif @@ -212,6 +214,11 @@ Returns the newly constructed xwidget, or nil if construction fails. */) G_CALLBACK (webkit_decide_policy_cb), xw); + + g_signal_connect (G_OBJECT (xw->widget_osr), + "mouse-target-changed", + G_CALLBACK (mouse_target_changed), + xw); } g_signal_connect (G_OBJECT (xw->widgetwindow_osr), "damage-event", @@ -572,6 +579,55 @@ find_widget_at_pos (GtkWidget *w, int x, int y, return NULL; } +static Emacs_Cursor +cursor_for_hit (WebKitHitTestResult *result, + struct frame *frame) +{ + Emacs_Cursor cursor = FRAME_OUTPUT_DATA (frame)->nontext_cursor; + + if (webkit_hit_test_result_context_is_editable (result) + || webkit_hit_test_result_context_is_selection (result) + || (webkit_hit_test_result_get_context (result) + & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)) + cursor = FRAME_X_OUTPUT (frame)->text_cursor; + + if (webkit_hit_test_result_context_is_scrollbar (result)) + cursor = FRAME_X_OUTPUT (frame)->vertical_drag_cursor; + + if (webkit_hit_test_result_context_is_link (result)) + cursor = FRAME_X_OUTPUT (frame)->hand_cursor; + + return cursor; +} + +static void +define_cursors (struct xwidget *xw, WebKitHitTestResult *res) +{ + struct xwidget_view *xvw; + + for (Lisp_Object tem = Vxwidget_view_list; CONSP (tem); + tem = XCDR (tem)) + { + xvw = XXWIDGET_VIEW (XCAR (tem)); + + if (XXWIDGET (xvw->model) == xw) + { + xvw->cursor = cursor_for_hit (res, xvw->frame); + if (xvw->wdesc != None) + XDefineCursor (xvw->dpy, xvw->wdesc, xvw->cursor); + } + } +} + +static void +mouse_target_changed (WebKitWebView *webview, + WebKitHitTestResult *hitresult, + guint modifiers, gpointer xw) +{ + define_cursors (xw, hitresult); +} + + static void xwidget_button_1 (struct xwidget_view *view, bool down_p, int x, int y, int button, @@ -1092,6 +1148,7 @@ xwidget_init_view (struct xwidget *xww, xv->wdesc = None; xv->frame = s->f; + xv->cursor = FRAME_X_OUTPUT (s->f)->nontext_cursor; #elif defined NS_IMPL_COCOA nsxwidget_init_view (xv, xww, s, x, y); nsxwidget_resize_view(xv, xww->width, xww->height); @@ -1204,6 +1261,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s) clip_bottom - clip_top, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWEventMask, &a); + XDefineCursor (xv->dpy, xv->wdesc, xv->cursor); xv->cr_surface = cairo_xlib_surface_create (xv->dpy, xv->wdesc, FRAME_DISPLAY_INFO (s->f)->visual, diff --git a/src/xwidget.h b/src/xwidget.h index 50d8271db19..e62502730d5 100644 --- a/src/xwidget.h +++ b/src/xwidget.h @@ -33,6 +33,7 @@ struct window; #if defined (USE_GTK) #include #include +#include "xterm.h" #elif defined (NS_IMPL_COCOA) && defined (__OBJC__) #import #import "nsxwidget.h" @@ -102,6 +103,7 @@ struct xwidget_view #if defined (USE_GTK) Display *dpy; Window wdesc; + Emacs_Cursor cursor; struct frame *frame; cairo_surface_t *cr_surface;