我尝试制作一个功能类似于底座的GNOME扩展程序,除了它显示状态信息(时间,电池等)。我在这里坚持的是,当光标进入特定像素区域时,如何显示信息?比如,如果屏幕是1600x900像素(仅作为示例),它应该在function gatherArtwork(_callback) {
// Read each of the mp3s to gather artwork ('url' == local var for mp3)
<% @related_titles.each do |url| %>
jsmediatags.read("<%= url['mp3'] %>", {
onSuccess: function(tag) {
console.log('Gathering album art for title...');
// Convert the image contents to a Base64 encoded str
var tags = tag.tags;
albumartwork = _arrayBufferToBase64(tags.picture["data"]);
// Append to the coverflow list a `<ul><li> </li></ul>` for each mp3
// The 'albumartwork' Base64 image str is also appended here
$("#coverflow-item-list").append('<ul><li>...</li></li>');
}
});
<% end %>
console.log('Gathered all art! Now I will callback and render the Coverflow');
_callback();
}
// Gather artwork MUST complete fully before the `makeitrain` function runs (callback)
function renderCoverflow() {
gatherArtwork(function() {
console.log('Initing Coverflow since gatherArtwork completed/we have art!');
makeitrain();
});
}
// Execute 'renderCoverflow' which will gather art and then "makeitrain"!
renderCoverflow();
和x>1550
时激活。这不是实际的像素范围,而是在一般区域中的某些东西。我的问题是,我怎样才能使它经常检查光标是否在该区域?我可以做一个while循环,但我认为这将是资源丰富的,必须有一个更好的方法。在那儿?到目前为止,我已经查看了其他扩展以及API的在线,但似乎我找不到任何可能有用的东西。我看到一个看起来很有前途的主环,但我并不是真的理解它。
提前致谢!
答案 0 :(得分:0)
Note, you can't use an infinite while loop since it would block the shell; you have to use the mainloop.
You can use the pointerWatcher (more convenient since they added idle monitor detection):
https://gitlab.gnome.org/GNOME/gnome-shell/blob/master/js/ui/pointerWatcher.js
Example:
let PointerWatcher = imports.ui.pointerWatcher;
let watcher = new PointerWatcher.PointerWatcher();
let watch = watcher.addWatch(50, (x, y) => {
let m = Main.layoutManager.currentMonitor;
if ((m.height - y) < 200 && (m.width - x) < 200) {
Main.notify("asdf");
}
});
// watch.remove();
There is also that Meta.Barrier thing. Might look into.