Skip to content

Commit

Permalink
Revert to use a refresh period instead of the pointer watcher
Browse files Browse the repository at this point in the history
This handles better some of the errors that are happening on some occasions while drawing the eye
  • Loading branch information
anaximeno committed Sep 22, 2024
1 parent 88912b4 commit aa536e6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions c-eyes@anaximeno/files/c-eyes@anaximeno/6.2/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const {
} = require("./constants.js");
const { Debouncer } = require("./helpers.js");

const PointerWatcher = require("./pointerWatcher.js").getPointerWatcher();

Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale");


Expand Down Expand Up @@ -78,6 +76,8 @@ class Eye extends Applet.Applet {
Util.setTimeout(this.on_property_updated.bind(this), WS_SWITCHED_UPDATE_TIMEOUT_MS);
}, this);

this.refresh_handler_id = 0;

this._last_mouse_x = undefined;
this._last_mouse_y = undefined;
this._last_eye_x = undefined;
Expand Down Expand Up @@ -252,11 +252,13 @@ class Eye extends Applet.Applet {
}
}

on_mouse_moved(x, y) {
if (this.should_redraw(x, y)) {
// global.log(UUID, `repainting with ${this.repaint_interval}ms interval, mouse pos = (${x}, ${y})`);
on_refresh_timeout() {
if (this.should_redraw()) {
// global.log(UUID, `repainting with ${this.repaint_interval}ms interval`);
this.area.queue_repaint();
}

return GLib.SOURCE_CONTINUE;
}

on_eye_mode_update() {
Expand Down Expand Up @@ -293,21 +295,21 @@ class Eye extends Applet.Applet {

set_active(enabled) {
this.enabled = enabled;
this.on_property_updated();

this.signals.disconnect('repaint', this.area);
if (this.pointerMovementListener) {
this.pointerMovementListener.remove();
this.pointerMovementListener = null;

if (this.refresh_handler_id) {
GLib.source_remove(this.refresh_handler_id);
this.refresh_handler_id = 0;
}

if (enabled) {
this.signals.connect(this.area, 'repaint', this.paint_eye, this);
this.pointerMovementListener = PointerWatcher.addWatch(
this.refresh_handler_id = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
this.repaint_interval,
this.on_mouse_moved.bind(this),
);
this.area.queue_repaint();
this.on_refresh_timeout.bind(this));
this.on_property_updated();
}

global.log(UUID, `Eye/${this.instanceId} ${enabled ? "enabled" : "disabled"}`);
Expand Down Expand Up @@ -378,7 +380,8 @@ class Eye extends Applet.Applet {
return [area_x, area_y];
}

should_redraw(mouse_x, mouse_y) {
should_redraw() {
const [mouse_x, mouse_y, _] = global.get_pointer();
const [ox, oy] = this.get_area_position();

let should_redraw = true;
Expand Down

0 comments on commit aa536e6

Please sign in to comment.