Recent

Author Topic: Prevent computer sleep  (Read 4819 times)

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Prevent computer sleep
« on: November 07, 2018, 02:23:31 pm »
Hi. I need help to modify my application to prevent computer entering sleep state while the app is doing something....
On windows i achieve this like so:
Code: Pascal  [Select]
  1. {$IFDEF Windows}
  2.    SetThreadExecutionState(ES_CONTINUOUS OR ES_SYSTEM_REQUIRED OR ES_AWAYMODE_REQUIRED);
  3. {$ENDIF}

Any ideea on how can i do this on Linux..manly Ubuntu 18.04 x64.
Thank you very much.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #1 on: November 12, 2018, 07:23:25 am »
No one? Any hint is appreciated... :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Prevent computer sleep
« Reply #2 on: November 12, 2018, 01:10:57 pm »
What I can find is this, where FPC should be capable of doing both, however I prefer the dbus way as X may not be available in the future when wayland finally takes over. See: http://wiki.freepascal.org/FPC_and_DBus

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: Prevent computer sleep
« Reply #3 on: November 12, 2018, 01:30:57 pm »
Yes, I agree, but the wiki entry is not finished and a bit marginal. There is far better code however:
If you are new to dbus programming maybe these articles by Michael can Canneyt can help:
https://www.freepascal.org/~michael/articles/#dbus1
https://www.freepascal.org/~michael/articles/#dbus2
sources: https://www.freepascal.org/~michael/articles/dbus2/dbus-code.zip
« Last Edit: November 12, 2018, 01:32:47 pm by Thaddy »
also related to equus asinus.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #4 on: November 14, 2018, 09:46:27 am »
Thank you both! :-)
@Thaddy The sorces posted for dbus does not compile anymore so i will try using dbus-sent in a Tprocess
Thank you again.

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: Prevent computer sleep
« Reply #5 on: November 14, 2018, 10:00:32 am »
Yes i Saw that. A quick Fix is to make the property a VAR
also related to equus asinus.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #6 on: November 14, 2018, 01:04:56 pm »
@Thaddy Please, can you be more specific?
What did you changed in order to compile the 2 bundled examples? Thank you.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #7 on: November 16, 2018, 10:12:11 am »
Me again...i am unable to sort this out... :/ It is beyond my skills.
Could someone provide an quick example how to call a dbus method using dbus unit from fpc? "dbuscomp" i am unable to make it to compile.
Thank you very much.

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: Prevent computer sleep
« Reply #8 on: November 16, 2018, 11:52:03 am »
check if  the dbus shared libraries have the extension .so and not so.1 or something. If so, create a symlink or copy.
also related to equus asinus.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #9 on: November 16, 2018, 02:51:04 pm »
check if  the dbus shared libraries have the extension .so and not so.1 or something. If so, create a symlink or copy.
This is not the problem.
I need an working examle using dbus unit as the wiki is incomplete or an updated dbuscomp unit which i could compile. The posted one has methods which are no longer available in dbus.
Thanks again.

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: Prevent computer sleep
« Reply #10 on: November 16, 2018, 03:12:17 pm »
OK I will come up with something new (but these calls are still available afaik AND tested!) Not based on the wiki but based on the article.
also related to equus asinus.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #11 on: November 17, 2018, 12:43:23 pm »
Thank you @Thaddy.  :D I am waiting eagerly for your example.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #12 on: November 22, 2018, 09:46:38 am »
Please, just an working example of using dbus...it's all i need... i hope... :-)

Thaddy

  • Hero Member
  • *****
  • Posts: 9303
Re: Prevent computer sleep
« Reply #13 on: November 22, 2018, 11:30:12 am »
I do not always have time to do it right away.
also related to equus asinus.

mdalacu

  • Full Member
  • ***
  • Posts: 202
    • dmSimpleApps
Re: Prevent computer sleep
« Reply #14 on: November 23, 2018, 07:49:37 am »
I do not always have time to do it right away.
I am sorry for insisting to much.