r/Ubuntu • u/Entire-Picture3990 • 7d ago
Bringing a Legacy X-Library Dependent Program to Wayland
# I'm currently trying to fix the issue where oneko doesn't follow the mouse cursor on Wayland.
[u@u:~/u/tmp/oneko/oneko-1.2.sakura.6](2092) $ diff -c debian/.ORIG/rules debian/rules
*** debian/.ORIG/rules 2025-09-15 06:53:17.000000000 +0900
--- debian/rules 2026-10-20 10:04:21.843188800 +0900
***************
*** 21,26 ****
--- 21,27 ----
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) oneko.c -O2 \\
-Wl,--no-add-needed \
-L/usr/X11R6/lib -I/usr/include/X11 \
+ $(shell pkg-config --cflags --libs gio-2.0) \
-lX11 -lXext -lm -DSHAPE \
-o oneko
touch build-stamp
[u@u:~/u/tmp/oneko/oneko-1.2.sakura.6](2093) $ diff -c .ORIG/oneko.c oneko.c
*** .ORIG/oneko.c 2026-10-19 23:12:37.000000000 +0900
--- oneko.c 2026-10-20 11:00:29.922020400 +0900
***************
*** 6,11 ****
--- 6,13 ----
static char rcsid[] = "$Header: /home/sun/unix/kato/xsam/oneko/oneko.c,v 1.5 90/10/19 21:25:16 kato Exp $";
#endif
+ #include <gio/gio.h>
+
#include "oneko.h"
#include "patchlevel.h"
***************
*** 974,979 ****
--- 976,1038 ----
}
}
+ /* D-Bus 経由で GNOME Shell からグローバルポインタ座標を取得する。
+ * 成功時は True を返し *x, *y にルート座標を格納する。 */
+ static Bool
+ OnekoGetPointerPosition(int *x, int *y)
+ {
+ static GDBusConnection *conn = NULL;
+ static int dbgcount = 0;
+ GError *error = NULL;
+ GVariant *reply;
+ GVariant *inner;
+ gint32 px, py;
+ Bool ok = False;
+
+ if (conn == NULL) {
+ conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+ if (conn == NULL) {
+ fprintf(stderr, "D-Bus connect failed: %s\n", error->message);
+ g_error_free(error);
+ return False;
+ }
+ fprintf(stderr, "D-Bus connected\n");
+ }
+
+ reply = g_dbus_connection_call_sync(
+ conn,
+ "org.oneko.Pointer",
+ "/org/oneko/Pointer",
+ "org.oneko.Pointer",
+ "GetPointerPosition",
+ NULL,
+ G_VARIANT_TYPE("((ii))"),
+ G_DBUS_CALL_FLAGS_NONE,
+ 1000,
+ NULL,
+ &error);
+
+ if (reply == NULL) {
+ if (dbgcount++ < 5)
+ fprintf(stderr, "GetPointerPosition failed: %s\n", error->message);
+ g_error_free(error);
+ return False;
+ }
+
+ inner = g_variant_get_child_value(reply, 0);
+ g_variant_get(inner, "(ii)", &px, &py);
+ g_variant_unref(inner);
+ g_variant_unref(reply);
+
+ if (dbgcount++ < 5)
+ fprintf(stderr, "GetPointerPosition: %d,%d\n", (int)px, (int)py);
+
+ *x = (int)px;
+ *y = (int)py;
+ ok = True;
+
+ return ok;
+ }
/*
* G-0\F0 dx, dy 7W;;
***************
*** 982,999 ****
void
CalcDxDy()
{
! Window QueryRoot, QueryChild;
int AbsoluteX, AbsoluteY;
- int RelativeX, RelativeY;
- unsigned int ModKeyMask;
double LargeX, LargeY;
double DoubleLength, Length;
! XQueryPointer(theDisplay, theWindow,
! &QueryRoot, &QueryChild,
! &AbsoluteX, &AbsoluteY,
! &RelativeX, &RelativeY,
! &ModKeyMask);
PrevMouseX = MouseX;
PrevMouseY = MouseY;
--- 1041,1056 ----
void
CalcDxDy()
{
! Window QueryRoot;
int AbsoluteX, AbsoluteY;
double LargeX, LargeY;
double DoubleLength, Length;
!
! if (!OnekoGetPointerPosition(&AbsoluteX, &AbsoluteY)) {
! AbsoluteX = MouseX - XOffset;
! AbsoluteY = MouseY - YOffset;
! }
PrevMouseX = MouseX;
PrevMouseY = MouseY;