Fix GNOME fractional-scale absolute pointer coordinates and add precise GTK target probe

This commit is contained in:
VallierDev committed 2026-10-15 02:10:59 +08:00
1 parent 06946568b7
commit 050b8710a8
3 files changed
+48 -2

No files matched your search

+13 -1
View File
@@ -46,6 +46,7 @@ struct uu_portal {
int error;
uint32_t node, width, height;
int logical_width, logical_height;
int absolute_stream_pixels;
enum spa_video_format format;
uint8_t *frame;
size_t frame_length;
@@ -271,6 +272,13 @@ struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)
*error = 0; *width = *height = 0;
struct uu_portal *p = calloc(1, sizeof(*p));
if (!p) { *error = 8; return NULL; }
/* GNOME forwards NotifyPointerMotionAbsolute into Mutter's stream-to-stage
* transform. It expects stream pixels, unlike the compositor-sized KDE path.
* Do not apply the compositor scale twice on fractional-scale displays. */
gchar **desktops = g_strsplit(g_getenv("XDG_CURRENT_DESKTOP") ? g_getenv("XDG_CURRENT_DESKTOP") : "", ":", -1);
for (gchar **desktop = desktops; *desktop; desktop++)
if (!g_ascii_strcasecmp(*desktop, "GNOME")) p->absolute_stream_pixels = 1;
g_strfreev(desktops);
pthread_mutex_init(&p->lock, NULL); pthread_cond_init(&p->changed, NULL);
p->context = g_main_context_new(); g_main_context_push_thread_default(p->context);
p->bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
@@ -359,6 +367,9 @@ struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)
p->dbus_started = 1;
*error = connect_pipewire(p);
if (*error) { uu_portal_close(p); return NULL; }
fprintf(stderr, "Portal pointer geometry: frame=%ux%u compositor=%dx%d absolute=%s\n",
p->width, p->height, p->logical_width, p->logical_height,
p->absolute_stream_pixels ? "stream-pixels" : "compositor-logical");
*width = p->width; *height = p->height;
return p;
done:
@@ -447,7 +458,8 @@ int uu_portal_move(struct uu_portal *p, double x, double y, int relative) {
x * p->logical_width / p->width, y * p->logical_height / p->height));
if (x < 0 || y < 0 || x >= p->width || y >= p->height) return 11;
return notify(p, "NotifyPointerMotionAbsolute", g_variant_new("(o@a{sv}udd)", p->session, empty_options(), p->node,
x * p->logical_width / p->width, y * p->logical_height / p->height));
p->absolute_stream_pixels ? x : x * p->logical_width / p->width,
p->absolute_stream_pixels ? y : y * p->logical_height / p->height));
}
int uu_portal_button(struct uu_portal *p, int button, int pressed) {
if (!p) return 11;
+29
View File
@@ -71,6 +71,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
let input=InputInjector::new();
input.bind_portal(screen.portal.clone());
if std::env::args().nth(2).as_deref() == Some("--clipboard-targets") {
let read = || -> Result<serde_json::Value, Box<dyn std::error::Error>> {
Ok(serde_json::from_slice(&std::fs::read("/tmp/uuremote-clipboard-official.json")?)?)
};
let before = read()?;
if before["native_wayland"] != true || before["window_active"] != true { return Err("Native clipboard fixture must be focused".into()); }
for name in ["check", "copy"] {
let bounds = before[format!("{name}_bounds")].as_array().ok_or("Missing test button bounds")?;
let number = |index: usize| bounds[index].as_f64().ok_or("Invalid button bounds");
let x = number(0)? + number(2)? / 2.0;
let y = number(1)? + number(3)? / 2.0;
let width = before["window_size"][0].as_f64().ok_or("Missing test window width")?;
let height = before["window_size"][1].as_f64().ok_or("Missing test window height")?;
input.mouse_absolute_normalized(x / width, y / height, (screen.width,screen.height));
input.mouse_button(1,true); input.mouse_button(1,false);
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
let after = read()?;
let key = format!("{name}_activations");
if after[&key].as_u64() != before[&key].as_u64().map(|n| n+1) {
return Err(format!("Portal small-target click missed: {name}").into());
}
let position = after["last_position"].as_array().ok_or("Missing native test pointer position")?;
if (position[0].as_f64().ok_or("Invalid pointer x")? - x).abs() > 2.0 || (position[1].as_f64().ok_or("Invalid pointer y")? - y).abs() > 2.0 {
return Err("Portal small-target pointer error exceeds two logical pixels".into());
}
println!("Portal native small-target click passed: {name}; pointer_error<=2px");
}
return Ok(());
}
input.mouse_absolute_normalized(0.25,0.25,(screen.width,screen.height));input.flush_pointer();
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
input.mouse_absolute_normalized(0.5,0.5,(screen.width,screen.height));input.flush_pointer();
+6 -1
View File
@@ -46,6 +46,11 @@ def activate(app):
gesture.connect('pressed',pressed_seen);window.add_controller(gesture)
window.present();window.fullscreen()
state['native_wayland']='wayland' in type(Gdk.Display.get_default()).__name__.lower()
def record(): report.write_text(json.dumps(state));return True
def record():
state['window_size']=[window.get_width(),window.get_height()]
for name,button in [('check',check),('copy',copy)]:
ok,bounds=button.compute_bounds(window)
if ok:state[name+'_bounds']=[bounds.get_x(),bounds.get_y(),bounds.get_width(),bounds.get_height()]
report.write_text(json.dumps(state));return True
GLib.timeout_add(200,record)
app.connect('activate',activate);app.run([])