Skip to content

Implement support for power events and preventing sleep/suspend in wxGTK - #25147

Merged
vadz merged 5 commits into
wxWidgets:masterfrom
vadz:gtk-power-events
Feb 12, 2025
Merged

Implement support for power events and preventing sleep/suspend in wxGTK#25147
vadz merged 5 commits into
wxWidgets:masterfrom
vadz:gtk-power-events

Conversation

@vadz

@vadz vadz commented Feb 8, 2025

Copy link
Copy Markdown
Contributor

This mainly addresses #23717 but also happens to implement #22396 as a side effect.

vadz added 3 commits February 6, 2025 20:00
No real changes, just show how this argument can be used.
Allow passing it to GTK or glib functions to be filled in by them.

The name of the function is consistent with wxGtkError, although not
with wxGtkVariant which uses ByRef().
vadz added 2 commits February 8, 2025 16:38
Implement wxPowerResource::Acquire(wxPOWER_RESOURCE_SYSTEM) for wxGTK
under Linux when using systemd.

Closes wxWidgets#22396.
Generate these events on the systems running systemd, which provides
org.freedesktop.login1 D-Bus interface, but require acquiring system
power resource with the special new wxPOWER_DELAY "block mode" in order
to do it.

This means that existing applications need to be updated in order to
start getting these events, but it has the advantage of avoiding to have
to open the D-Bus connection on startup of every program, even if it's
never going to use it, and also forces the program to provide the
explanatory message, which is nice to have as it is shown by tools such
as systemd-inhibit to show what could be preventing system sleep.

Closes wxWidgets#23717.
@vadz
vadz force-pushed the gtk-power-events branch from eb7f476 to e549a2b Compare February 8, 2025 15:38
@vadz
vadz merged commit 58fe758 into wxWidgets:master Feb 12, 2025
@vadz
vadz deleted the gtk-power-events branch February 12, 2025 17:16
@MaartenBent

Copy link
Copy Markdown
Contributor

I'm getting link errors:

/usr/bin/ld: ../lib/libwx_gtk3u_core-3.3.so.0.0.0: undefined reference to `vtable for wxPowerEvent'
/usr/bin/ld: ../lib/libwx_gtk3u_core-3.3.so.0.0.0: undefined reference to `wxEVT_POWER_SUSPENDED'
/usr/bin/ld: ../lib/libwx_gtk3u_core-3.3.so.0.0.0: undefined reference to `wxEVT_POWER_RESUME'

I think caused by this line. The events are implemented in powercmn.cpp, part of the base library. This doesn't have the __WXGTK__ define. It works when I change it to __UNIX__, though that maybe breaks macOS.

#if defined(__WINDOWS__) || defined(__WXGTK__)

@vadz

vadz commented Feb 16, 2025

Copy link
Copy Markdown
Contributor Author

Oops, it indeed looks like this can't work (so I wonder how does it manage to work nevertheless for me and in the CI builds too, and what's the difference with your build).

Worse, I'm not sure how to fix it. I think we're going to need to move all wxPowerXXX stuff to core from base. Or we'd need to virtualize it via wxAppTraits, but this would be more complicated and probably not really worth it, or would it be?

@MaartenBent

Copy link
Copy Markdown
Contributor

Not sure what is different, my build should be the same as CMake builds - Ubuntu 22.04 wxGTK 3. The libraries build fine, it is the samples that fail to link.
I'm ok with moving it to core. But I don't know if there are cases where power events are used in console / base-only applications.

@lanurmi

lanurmi commented Feb 16, 2025

Copy link
Copy Markdown
Contributor

It would make perfect sense for a Windows service (using base only) to prevent sleep. However, I'm unsure whether SetThreadExecutionState() actually works with services as the documentation suggests "desktop apps only". Nonetheless, such code can exist and does exist.

@vadz

vadz commented Feb 17, 2025

Copy link
Copy Markdown
Contributor Author

It's going to be a lot of work to make this available in MSW console applications and I don't think it's worth it, so for now I've only created #25174. If we really, really need them in base, they could be virtualized later but, again, I just don't think it's worth investing time into this.

vadz added a commit that referenced this pull request Feb 17, 2025
These classes can't be implemented in the base library any more as the
Linux implementation uses glib and so can only be part of wxGTK.

See #25147.

Closes #25174.
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 this pull request may close these issues.

3 participants