Skip to content

Commit

Permalink
core: implement wlr-output-power-management-unstable-v1
Browse files Browse the repository at this point in the history
Fixes #444
Fixes #455
  • Loading branch information
ammen99 committed May 18, 2020
1 parent 70408cc commit 297eee2
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 2 deletions.
3 changes: 2 additions & 1 deletion proto/meson.build
Expand Up @@ -31,7 +31,8 @@ server_protocols = [
[wl_protocol_dir, 'unstable/tablet/tablet-unstable-v2.xml'],
'wayfire-shell-unstable-v2.xml',
'gtk-shell.xml',
'wlr-layer-shell-unstable-v1.xml'
'wlr-layer-shell-unstable-v1.xml',
'wlr-output-power-management-unstable-v1.xml'
]

wl_protos_src = []
Expand Down
128 changes: 128 additions & 0 deletions proto/wlr-output-power-management-unstable-v1.xml
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_output_power_management_unstable_v1">
<copyright>
Copyright © 2019 Purism SPC

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>

<description summary="Control power management modes of outputs">
This protocol allows clients to control power management modes
of outputs that are currently part of the compositor space. The
intent is to allow special clients like desktop shells to power
down outputs when the system is idle.

To modify outputs not currently part of the compositor space see
wlr-output-management.

Warning! The protocol described in this file is experimental and
backward incompatible changes may be made. Backward compatible changes
may be added together with the corresponding interface version bump.
Backward incompatible changes are done by bumping the version number in
the protocol and interface names and resetting the interface version.
Once the protocol is to be declared stable, the 'z' prefix and the
version number in the protocol and interface names are removed and the
interface version number is reset.
</description>

<interface name="zwlr_output_power_manager_v1" version="1">
<description summary="manager to create per-output power management">
This interface is a manager that allows creating per-output power
management mode controls.
</description>

<request name="get_output_power">
<description summary="get a power management for an output">
Create a output power management mode control that can be used to
adjust the power management mode for a given output.
</description>
<arg name="id" type="new_id" interface="zwlr_output_power_v1"/>
<arg name="output" type="object" interface="wl_output"/>
</request>

<request name="destroy" type="destructor">
<description summary="destroy the manager">
All objects created by the manager will still remain valid, until their
appropriate destroy request has been called.
</description>
</request>
</interface>

<interface name="zwlr_output_power_v1" version="1">
<description summary="adjust power management mode for an output">
This object offers requests to set the power management mode of
an output.
</description>

<enum name="mode">
<entry name="off" value="0"
summary="Output is turned off."/>
<entry name="on" value="1"
summary="Output is turned on, no power saving"/>
</enum>

<enum name="error">
<entry name="invalid_mode" value="1" summary="inexistent power save mode"/>
</enum>

<request name="set_mode">
<description summary="Set an outputs power save mode">
Set an output's power save mode to the given mode. The mode change
is effective immediately. If the output does not support the given
mode a failed event is sent.
</description>
<arg name="mode" type="uint" enum="mode" summary="the power save mode to set"/>
</request>

<event name="mode">
<description summary="Report a power management mode change">
Report the power management mode change of an output.

The mode event is sent after an output changed its power
management mode. The reason can be a client using set_mode or the
compositor deciding to change an output's mode.
This event is also sent immediately when the object is created
so the client is informed about the current power management mode.
</description>
<arg name="mode" type="uint" enum="mode"
summary="the output's new power management mode"/>
</event>

<event name="failed">
<description summary="object no longer valid">
This event indicates that the output power management mode control
is no longer valid. This can happen for a number of reasons,
including:
- The output doesn't support power management
- Another client already has exclusive power management mode control
for this output
- The output disappeared

Upon receiving this event, the client should destroy this object.
</description>
</event>

<request name="destroy" type="destructor">
<description summary="destroy this power management">
Destroys the output power management mode control object.
</description>
</request>
</interface>
</protocol>
1 change: 0 additions & 1 deletion src/core/core-impl.hpp
Expand Up @@ -80,7 +80,6 @@ class compositor_core_impl_t : public compositor_core_t
pid_t run(std::string command) override;

private:
wf::wl_listener_wrapper output_layout_changed;
wf::wl_listener_wrapper decoration_created;
wf::wl_listener_wrapper xdg_decoration_created;
wf::wl_listener_wrapper vkbd_created;
Expand Down
23 changes: 23 additions & 0 deletions src/core/output-layout.cpp
Expand Up @@ -28,6 +28,7 @@ extern "C"
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_output_power_management_v1.h>
#include <wlr/render/wlr_renderer.h>
#undef static
}
Expand Down Expand Up @@ -813,10 +814,13 @@ namespace wf

wlr_output_layout *output_layout;
wlr_output_manager_v1 *output_manager;
wlr_output_power_manager_v1 *output_pw_manager;

wl_listener_wrapper on_new_output;
wl_listener_wrapper on_output_manager_test;
wl_listener_wrapper on_output_manager_apply;
wl_listener_wrapper on_output_power_mode_set;

wl_idle_call idle_init_noop;
wl_idle_call idle_update_configuration;
wl_timer timer_remove_noop;
Expand Down Expand Up @@ -871,6 +875,12 @@ namespace wf

on_output_manager_test.connect(&output_manager->events.test);
on_output_manager_apply.connect(&output_manager->events.apply);

output_pw_manager = wlr_output_power_manager_v1_create(get_core().display);
on_output_power_mode_set.set_callback([=] (void *data) {
set_power_mode((wlr_output_power_v1_set_mode_event*)data);
});
on_output_power_mode_set.connect(&output_pw_manager->events.set_mode);
}

~impl()
Expand Down Expand Up @@ -1179,6 +1189,19 @@ namespace wf
wlr_configuration);
}

void set_power_mode(wlr_output_power_v1_set_mode_event *ev)
{
LOGD("output: ", ev->output->name, " power mode: ", ev->mode);
auto config = get_current_configuration();
if (!config.count(ev->output))
return;

config[ev->output].source =
(ev->mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ?
OUTPUT_IMAGE_SOURCE_SELF : OUTPUT_IMAGE_SOURCE_DPMS);
apply_configuration(config);
}

/* Public API functions */
wlr_output_layout *get_handle() { return output_layout; }
size_t get_num_outputs() { return get_outputs().size(); }
Expand Down

0 comments on commit 297eee2

Please sign in to comment.