Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Igalia/cog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 92e8c4e5ef61e6b5e3ee48d8c68594a0654ac46c
Choose a base ref
..
head repository: Igalia/cog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 10b5bbd292b3c81f26fac62cdd4aef1ff9562851
Choose a head ref
4 changes: 2 additions & 2 deletions core/cog-view.c
Original file line number Diff line number Diff line change
@@ -125,8 +125,8 @@ cog_view_class_init(CogViewClass *klass)
*
* Since: 0.20
*/
s_properties[PROP_VIEWPORT] = g_param_spec_object("viewport", NULL, NULL, G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
s_properties[PROP_VIEWPORT] =
g_param_spec_object("viewport", NULL, NULL, G_TYPE_OBJECT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);

g_object_class_install_properties(object_class, N_PROPERTIES, s_properties);
}
44 changes: 44 additions & 0 deletions platform/common/cog-cursors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* cog-cursor-names.h
* Copyright (C) 2023 Igalia S.L.
* Copyright (C) 2023 SUSE Software Solutions Germany GmbH
*
* SPDX-License-Identifier: MIT
*/

#include "cog-cursors.h"
#include <wpe/webkit.h>

CogCursorNames
cog_cursors_get_names(CogCursorType type)
{
static const char *const default_names[] = {"default", "left_ptr", NULL};
static const char *const hand_names[] = {"pointer", "hand", "hand1", "pointing_hand", NULL};
static const char *const text_names[] = {"text", "xterm", "ibeam", NULL, NULL};

switch (type) {
case COG_CURSOR_TYPE_DEFAULT:
return default_names;
case COG_CURSOR_TYPE_HAND:
return hand_names;
case COG_CURSOR_TYPE_TEXT:
return text_names;
default:
g_assert_not_reached();
return default_names;
}
}

CogCursorType
cog_cursors_get_type_for_hit_test(WebKitHitTestResult *hit_test)
{
g_assert(WEBKIT_IS_HIT_TEST_RESULT(hit_test));

if (webkit_hit_test_result_context_is_link(hit_test))
return COG_CURSOR_TYPE_HAND;

if (webkit_hit_test_result_context_is_editable(hit_test) || webkit_hit_test_result_context_is_selection(hit_test))
return COG_CURSOR_TYPE_TEXT;

return COG_CURSOR_TYPE_DEFAULT;
}
27 changes: 27 additions & 0 deletions platform/common/cog-cursors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* cog-cursors.h
* Copyright (C) 2023 SUSE Software Solutions Germany GmbH
*
* SPDX-License-Identifier: MIT
*/

#pragma once

typedef struct _WebKitHitTestResult WebKitHitTestResult;

typedef enum {
COG_CURSOR_TYPE_DEFAULT,
COG_CURSOR_TYPE_HAND,
COG_CURSOR_TYPE_TEXT,
} CogCursorType;

typedef const char *const *CogCursorNames;

CogCursorNames cog_cursors_get_names(CogCursorType type);
CogCursorType cog_cursors_get_type_for_hit_test(WebKitHitTestResult *hit_test);

static inline CogCursorNames
cog_cursors_get_names_for_hit_test(WebKitHitTestResult *hit_test)
{
return cog_cursors_get_names(cog_cursors_get_type_for_hit_test(hit_test));
}
23 changes: 0 additions & 23 deletions platform/common/cursors.h

This file was deleted.

1 change: 1 addition & 0 deletions platform/common/meson.build
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ endif

cogplatformcommon_lib = static_library('cogplatformcommon',
'cog-gl-utils.c',
'cog-cursors.c',
cogplatformcommon_sources,
dependencies: cogplatformcommon_dependencies,
build_by_default: false,
28 changes: 8 additions & 20 deletions platform/gtk4/cog-platform-gtk4.c
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@
#if COG_HAVE_LIBPORTAL
# include "../common/cog-file-chooser.h"
#endif /* COG_HAVE_LIBPORTAL */
#include "../common/cog-cursors.h"
#include "../common/cog-gl-utils.h"
#include "../common/cursors.h"
#include "cog-gtk-settings-dialog.h"

#define DEFAULT_WIDTH 1280
@@ -752,36 +752,24 @@ on_back_forward_changed(WebKitBackForwardList* back_forward_list,
gtk_widget_set_sensitive(win->forward_button,
webkit_web_view_can_go_forward(win->web_view));
}

static void
set_cursor(enum cursor_type type)
on_mouse_target_changed(WebKitWebView *view, WebKitHitTestResult *hitTestResult, guint mouseModifiers)
{
CogCursorNames cursor_names = cog_cursors_get_names_for_hit_test(hitTestResult);

g_autoptr(GdkCursor) cursor = NULL;
for (int i = 0; !cursor && i < G_N_ELEMENTS(cursor_names[type]) && cursor_names[type][i]; i++) {
cursor = gdk_cursor_new_from_name(cursor_names[type][i], NULL);
}
for (unsigned i = 0; !cursor && cursor_names[i]; i++)
cursor = gdk_cursor_new_from_name(cursor_names[i], NULL);

if (!cursor) {
g_warning("Could not get %s cursor", cursor_names[type][0]);
g_warning("Could not get %s cursor", cursor_names[0]);
return;
}

gtk_widget_set_cursor(win.gtk_window, cursor);
}

static void
on_mouse_target_changed(WebKitWebView *view, WebKitHitTestResult *hitTestResult, guint mouseModifiers)
{
if (webkit_hit_test_result_context_is_link(hitTestResult)) {
set_cursor(CURSOR_HAND);
} else if (webkit_hit_test_result_context_is_editable(hitTestResult)) {
set_cursor(CURSOR_TEXT);
} else if (webkit_hit_test_result_context_is_selection(hitTestResult)) {
set_cursor(CURSOR_TEXT);
} else {
set_cursor(CURSOR_LEFT_PTR);
}
}

#if COG_HAVE_LIBPORTAL
static void
on_run_file_chooser(WebKitWebView *view, WebKitFileChooserRequest *request)
41 changes: 29 additions & 12 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon.h>

#include "../common/cursors.h"
#include "../common/cog-cursors.h"
#include "../common/egl-proc-address.h"
#include "os-compatibility.h"

@@ -240,6 +240,10 @@ pointer_on_enter(void *data,
wl_fixed_t fixed_x,
wl_fixed_t fixed_y)
{
// We might be reading pending events after destroying the surface.
if (!surface)
return;

CogWlSeat *seat = data;

if (pointer != seat->pointer_obj) {
@@ -257,7 +261,7 @@ pointer_on_enter(void *data,
seat->pointer.surface = surface;

#ifdef COG_USE_WAYLAND_CURSOR
cog_wl_seat_set_cursor(seat, CURSOR_LEFT_PTR);
cog_wl_seat_set_cursor(seat, NULL);
#endif /* COG_USE_WAYLAND_CURSOR */
}

@@ -350,11 +354,11 @@ pointer_on_button(void *data,
cog_popup_menu_handle_event(
popup->popup_menu, !!state ? COG_POPUP_MENU_EVENT_STATE_PRESSED : COG_POPUP_MENU_EVENT_STATE_RELEASED,
event.x, event.y);
cog_wl_platform_popup_update(platform);
cog_wl_platform_popup_update();
return;
} else {
if (!!state)
cog_wl_platform_popup_destroy(platform);
cog_wl_platform_popup_destroy();
}
}

@@ -509,6 +513,10 @@ keyboard_on_enter(void *data,
struct wl_surface *surface,
struct wl_array *keys)
{
// We might be reading pending events after destroying the surface.
if (!surface)
return;

CogWlSeat *seat = data;

if (wl_keyboard != seat->keyboard_obj) {
@@ -717,6 +725,10 @@ touch_on_down(void *data,
wl_fixed_t x,
wl_fixed_t y)
{
// We might be reading pending events after destroying the surface.
if (!surface)
return;

CogWlSeat *seat = data;
CogWlDisplay *display = seat->display;

@@ -752,10 +764,10 @@ touch_on_down(void *data,
if (seat->touch.surface == popup->wl_surface) {
cog_popup_menu_handle_event(popup->popup_menu, COG_POPUP_MENU_EVENT_STATE_PRESSED, raw_event.x,
raw_event.y);
cog_wl_platform_popup_update(platform);
cog_wl_platform_popup_update();
return;
} else
cog_wl_platform_popup_destroy(platform);
cog_wl_platform_popup_destroy();
}

struct wpe_input_touch_event event = {seat->touch.points, 10, raw_event.type, raw_event.id, raw_event.time};
@@ -797,7 +809,7 @@ touch_on_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time,
if (target_surface == popup->wl_surface) {
cog_popup_menu_handle_event(popup->popup_menu, COG_POPUP_MENU_EVENT_STATE_RELEASED, raw_event.x,
raw_event.y);
cog_wl_platform_popup_update(platform);
cog_wl_platform_popup_update();

memset(&seat->touch.points[id], 0x00, sizeof(struct wpe_input_touch_event_raw));
return;
@@ -1351,7 +1363,7 @@ cog_wl_platform_finalize(GObject *object)

cog_wl_text_input_clear(platform);
if (platform->popup)
cog_wl_platform_popup_destroy(platform);
cog_wl_platform_popup_destroy();
clear_egl(platform->display);
clear_wayland(platform);

@@ -1373,24 +1385,29 @@ cog_wl_platform_create_im_context(CogPlatform *platform)
}

void
cog_wl_platform_popup_create(CogWlPlatform *platform, WebKitOptionMenu *option_menu)
cog_wl_platform_popup_create(CogWlViewport *viewport, WebKitOptionMenu *option_menu)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();
g_assert(!platform->popup);

CogWlPopup *popup = cog_wl_popup_create(platform, option_menu);
CogWlPopup *popup = cog_wl_popup_create(viewport, option_menu);
platform->popup = popup;
}

void
cog_wl_platform_popup_destroy(CogWlPlatform *platform)
cog_wl_platform_popup_destroy(void)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();

g_assert(platform->popup);
g_clear_pointer(&platform->popup, cog_wl_popup_destroy);
}

void
cog_wl_platform_popup_update(CogWlPlatform *platform)
cog_wl_platform_popup_update(void)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();

g_assert(platform->popup);
cog_wl_popup_update(platform->popup);
}
6 changes: 3 additions & 3 deletions platform/wayland/cog-platform-wl.h
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@ struct _CogWlPlatform {
*
* Returns: (void)
*/
void cog_wl_platform_popup_create(CogWlPlatform *, WebKitOptionMenu *);
void cog_wl_platform_popup_destroy(CogWlPlatform *);
void cog_wl_platform_popup_update(CogWlPlatform *);
void cog_wl_platform_popup_create(CogWlViewport *, WebKitOptionMenu *);
void cog_wl_platform_popup_destroy(void);
void cog_wl_platform_popup_update(void);

G_END_DECLS
18 changes: 10 additions & 8 deletions platform/wayland/cog-utils-wl.c
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon.h>

#include "../common/cursors.h"
#include "../common/cog-cursors.h"

#include "cog-im-context-wl-v1.h"
#include "cog-im-context-wl.h"
@@ -274,10 +274,10 @@ xdg_surface_on_configure(void *data, struct xdg_surface *surface, uint32_t seria
}

CogWlPopup *
cog_wl_popup_create(CogWlPlatform *platform, WebKitOptionMenu *option_menu)
cog_wl_popup_create(CogWlViewport *viewport, WebKitOptionMenu *option_menu)
{
CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get();
CogWlDisplay *display = platform->display;
CogWlViewport *viewport = COG_WL_VIEWPORT(platform->viewport);

CogWlPopup *popup = g_slice_new0(CogWlPopup);
g_debug("%s: Create @ %p", G_STRFUNC, popup);
@@ -446,20 +446,22 @@ cog_wl_seat_get_serial(CogWlSeat *seat)

#ifdef COG_USE_WAYLAND_CURSOR
void
cog_wl_seat_set_cursor(CogWlSeat *seat, enum cursor_type type)
cog_wl_seat_set_cursor(CogWlSeat *seat, WebKitHitTestResult *hit_test)
{
CogWlDisplay *display = seat->display;

if (!display->cursor_theme || !display->cursor_surface)
return;

CogCursorNames cursor_names =
hit_test ? cog_cursors_get_names_for_hit_test(hit_test) : cog_cursors_get_names(COG_CURSOR_TYPE_DEFAULT);

struct wl_cursor *cursor = NULL;
for (int i = 0; !cursor && i < G_N_ELEMENTS(cursor_names[type]) && cursor_names[type][i]; i++) {
cursor = wl_cursor_theme_get_cursor(display->cursor_theme, cursor_names[type][i]);
}
for (int i = 0; !cursor && cursor_names[i]; i++)
cursor = wl_cursor_theme_get_cursor(display->cursor_theme, cursor_names[i]);

if (!cursor) {
g_warning("Could not get %s cursor", cursor_names[type][0]);
g_warning("Could not get %s cursor", cursor_names[0]);
return;
}

6 changes: 4 additions & 2 deletions platform/wayland/cog-utils-wl.h
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#pragma once

#include "../../core/cog.h"
#include "../common/cog-cursors.h"

#if COG_HAVE_LIBPORTAL
# include "cog-xdp-parent-wl.h"
@@ -51,6 +52,7 @@ typedef struct _CogWlWindow CogWlWindow;
typedef struct _CogWlXkb CogWlXkb;

typedef struct _CogWlPlatform CogWlPlatform;
typedef struct _CogWlViewport CogWlViewport;

struct _CogWlAxis {
bool has_delta;
@@ -299,14 +301,14 @@ CogWlDisplay *cog_wl_display_create(const char *name, GError **error);
void cog_wl_display_destroy(CogWlDisplay *self);
CogWlOutput *cog_wl_display_find_output(CogWlDisplay *, struct wl_output *);

CogWlPopup *cog_wl_popup_create(CogWlPlatform *, WebKitOptionMenu *);
CogWlPopup *cog_wl_popup_create(CogWlViewport *, WebKitOptionMenu *);
void cog_wl_popup_destroy(CogWlPopup *);
void cog_wl_popup_display(CogWlPopup *);
void cog_wl_popup_update(CogWlPopup *);

CogWlSeat *cog_wl_seat_create(struct wl_seat *, uint32_t);
void cog_wl_seat_destroy(CogWlSeat *);
void cog_wl_seat_set_cursor(CogWlSeat *, enum cursor_type);
void cog_wl_seat_set_cursor(CogWlSeat *, WebKitHitTestResult *);
uint32_t cog_wl_seat_get_serial(CogWlSeat *);

void cog_wl_text_input_clear(CogWlPlatform *);
Loading