Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow apps to block screen locking/screensaver #4534

Closed
2 tasks done
mbaklor opened this issue Jan 10, 2024 · 9 comments · Fixed by #4538
Closed
2 tasks done

Allow apps to block screen locking/screensaver #4534

mbaklor opened this issue Jan 10, 2024 · 9 comments · Fixed by #4538

Comments

@mbaklor
Copy link
Contributor

mbaklor commented Jan 10, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

I was thinking of building a mobile monitoring app, and wanted the screen to remain on while the app is running.

I looked into it and there are simple native APIs for it.

On iOS you can call

[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
    [UIApplication sharedApplication].idleTimerDisabled = YES;
}];

(Thanks Andy for finding this, I only found the Swift API)

On Android it's split into two options, either keep screen on or keep CPU running, not entirely sure we need the latter and the former doesn't require permissions:

public class MainActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  }
}

https://developer.android.com/develop/background-work/background-tasks/scheduling/wakelock
It looks like there's also a C version of this code but I could only find mention of it and not the API itself.

Is it possible to construct a solution with the existing API?

No response

Describe the solution you'd like to see.

I think probably just add to the mobile driver API a method that calls the native APIs, preferably something that can be set and reset, so you can keep screen on for specific long lasting tasks and let it lock otherwise

@Jacalz
Copy link
Member

Jacalz commented Jan 10, 2024

Why should it be mobile specific? I think something similar would be very useful for some kinds of applications on desktop as well

@mbaklor
Copy link
Contributor Author

mbaklor commented Jan 10, 2024

Oh I guess I didn't think about it, is screen lock blocking an api that exists on desktop? Most of my PCs I use without auto locking and auto screen dimming so I really just didn't think of it. I'll give a looksee tomorrow if these features exist on desktops and how

@Jacalz
Copy link
Member

Jacalz commented Jan 10, 2024

Any video player is usually a good example of inhibiting the screen from sleeping/locking :)

@mbaklor
Copy link
Contributor Author

mbaklor commented Jan 11, 2024

Okay, looks like mac is the same is ios, so that's easy enough.

Linux gives XScreenSaverSuspend(display, bool) from here: https://linux.die.net/man/3/xscreensaversuspend

Windows has SetThreadExecutionState(flags) from here: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

@Jacalz
Copy link
Member

Jacalz commented Jan 11, 2024

Cool. Thanks for looking up support. Linux is probably not that simple though. We need a solution that works on both X11 and on Wayland but it's probably not a huge problem. I think the XDG Portal API might have something for it

@mbaklor
Copy link
Contributor Author

mbaklor commented Jan 11, 2024

Okay took a little finding (their docs are messy imo) but looks like the XDG portal equivalent is org.freedesktop.ScreenSaver.Inhibit
https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-org.freedesktop.portal.Inhibit

@Jacalz
Copy link
Member

Jacalz commented Jan 11, 2024

Thanks. Yeah, I should probably have attached that link to my previous message. I'm the one that has implemented the portal APIs on our develop branch. See https://github.com/rymdport/portal for reference.

Should probably not be too hard to hook up support for that one as well :)

@andydotxyz
Copy link
Member

iOS and Android are on that PR :)

@dweymouth dweymouth changed the title Allow mobile apps to block screen locking Allow apps to block screen locking/screensaver Jan 12, 2024
@andydotxyz
Copy link
Member

Desktop support now added too, this will be in v2.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants