Eclipse RCP 应用程序 - 如何检测应用程序何时空闲?

发布于 2024-10-10 07:49:26 字数 336 浏览 0 评论 0原文

我正在编写一个 Eclipse RCP 应用程序,除了我自己的插件之外,该应用程序还将有其他插件贡献,并且需要确定应用程序何时空闲(即一段时间内没有活动、应用程序最小化等)以及何时发生变化(即应用程序返回前台、单击鼠标等)。

我遇到的问题是,我要捕获所有应用程序击键和鼠标移动/单击...使用它来重置计时器,当计时器被击中时,可能会发生一些空闲处理(即通知服务器闲散 - 然后当我们切换到活跃状态时 - 没有什么密集的)。但是,应用程序窗口 shell 不会接收各种视图的子事件等,因此要么我遗漏了某些内容,要么这是错误的方法。

谁能提供解决方案吗?我不是在寻找系统范围的空闲 - 只是应用程序的空闲。

谢谢。

I am writing an Eclipse RCP application that will have other plugin contributions besides my own, and need to determine when the application is idle (i.e. no activity for a period of time, application is minimized, etc.), and when that changes (i.e. application is brought back to the foreground, a mouse is clicked, etc.).

The problem I'm having is that I was going to capture all application keystrokes and mouse moves/clicks...using that to reset a timer, and when the timer is hit, then some idle processing can occur (i.e. informing a server of the idleness - and then again when we switch to active - nothing intensive). However, the application window shell does not receive child events for the various views, etc. so either I'm missing something, or this is the wrong approach.

Can anyone offer a solution? I'm not looking for system-wide idleness - just application idleness.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巡山小妖精 2024-10-17 07:49:26

Eclipse IDE 已经有类似执行垃圾收集的功能,看一下 Bundle org.eclipse.ui.ide.application 中的 org.eclipse.ui.internal.ide.application.IDEIdleHelper 类

The Eclipse IDE already has something similar to perform Garbage Collection, take a look at the class org.eclipse.ui.internal.ide.application.IDEIdleHelper in Bundle org.eclipse.ui.ide.application

笑梦风尘 2024-10-17 07:49:26

也许这

    display.addFilter(SWT.MouseDown, new Listener() {
        @Override
        public void handleEvent(Event event) {
        }
    });

就是您正在寻找的(您也可以添加其他事件)?

这是在组件明智地完成事件处理之前执行的...

但是通常不建议使用它 - 它应该是一个非常有限的用例,所以。

Maybe that

    display.addFilter(SWT.MouseDown, new Listener() {
        @Override
        public void handleEvent(Event event) {
        }
    });

is what you're looking for (you can add other events, too)?

This is executed before event handling is done component wise...

But its use is not generally recommended - it should be a very restricted use case, so.

初见终念 2024-10-17 07:49:26

您可以利用以下事实:当没有更多消息需要处理时,readAndDispatch 方法将返回 false。像这样的事情:

long lastActivityAt = 0;
int idleThresholdSecs = 5;
while (true)
{
    while (display.readAndDispatch())
    {
        lastActivityAt = System.nanoTime();
    }

    if (System.nanoTime() - lastActivityAt > idleThresholdSecs * 1000 * 1000 * 1000) 
    {
        // we have been idle for at least "idleThresholdSecs"
        ...
    } 
    else
    {
        Thread.sleep(50);
    }
}

You can use the fact that the readAndDispatch method will return false when there are no more messages to process. Something like this:

long lastActivityAt = 0;
int idleThresholdSecs = 5;
while (true)
{
    while (display.readAndDispatch())
    {
        lastActivityAt = System.nanoTime();
    }

    if (System.nanoTime() - lastActivityAt > idleThresholdSecs * 1000 * 1000 * 1000) 
    {
        // we have been idle for at least "idleThresholdSecs"
        ...
    } 
    else
    {
        Thread.sleep(50);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文