2 * Copyright © 2020 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include "ivi-compositor.h"
31 /* default state, invalid should at least be in order
33 #ifndef AGL_SHELL_POLICY_STATE_INVALID
34 #define AGL_SHELL_POLICY_STATE_INVALID 0
38 #ifndef AGL_SHELL_POLICY_EVENT_SHOW
39 #define AGL_SHELL_POLICY_EVENT_SHOW 0
42 #ifndef AGL_SHELL_POLICY_EVENT_HIDE
43 #define AGL_SHELL_POLICY_EVENT_HIDE 1
51 struct wl_list link; /* ivi_policy::states or ivi_policy::events */
55 struct ivi_policy *policy;
61 struct ivi_output *output;
62 struct wl_event_source *timer; /* for policies that have a timeout */
64 struct wl_list link; /* ivi_policy::ivi_policies */
67 struct ivi_policy_api {
70 bool (*surface_create)(struct ivi_surface *surf, void *user_data);
71 bool (*surface_commited)(struct ivi_surface *surf, void *user_data);
72 bool (*surface_activate)(struct ivi_surface *surf, void *user_data);
73 bool (*surface_deactivate)(struct ivi_surface *surf, void *user_data);
75 bool (*surface_activate_by_default)(struct ivi_surface *surf, void *user_data);
77 /** see also ivi_policy_add(). If set this will be executed before
78 * adding a new policy rule */
79 bool (*policy_rule_allow_to_add)(void *user_data);
81 /** this callback will be executed when a there's a policy state change */
82 void (*policy_rule_try_event)(struct ivi_a_policy *a_policy);
86 struct ivi_compositor *ivi;
87 /* user-defined hooks */
88 struct ivi_policy_api api;
91 /* represents the policy rules */
92 struct wl_list policies; /* ivi_a_policy::link */
94 /* no state update chnage is being done as long as we have the same
96 uint32_t current_state;
97 uint32_t previous_state;
99 /* guards against current in change in progress */
100 bool state_change_in_progress;
102 /* additional states which can be verified in
103 * ivi_policy_api::policy_rule_try_event() */
104 struct wl_list states; /* state_event::link */
105 struct wl_list events; /* state_event::link */
107 /* necessary to for signaling the state change */
108 struct wl_listener listener_check_policies;
109 struct wl_signal signal_state_change;
113 /** Initialize the policy setup
115 * Policy engine should call ivi_policy_create() with its own ivi_policy_api
119 ivi_policy_create(struct ivi_compositor *compositor,
120 const struct ivi_policy_api *api, void *user_data);
122 /** Destroys the policy setup
126 ivi_policy_destroy(struct ivi_policy *ivi_policy);
128 /** Add a policy rule.
130 * ivi_policy_api::policy_rule_allow_to_add() can be used to limit adding
133 * Returns 0 in case of success, or -1 in case of failure.
137 ivi_policy_add(struct ivi_policy *policy, const char *app_id, uint32_t state,
138 uint32_t event, uint32_t timeout, struct wl_resource *output_res);
140 /** Trigger a state change. This should be called **each time** there is a need
141 * to apply the policy rules.
143 * Returns 0 in case of success, or -1 in case of failure.
146 ivi_policy_state_change(struct ivi_policy *policy, uint32_t state);
149 /** Add a new state. The state can be verified in ivi_policy_api::policy_rule_try_event()
153 ivi_policy_add_state(struct ivi_policy *policy, uint32_t state, const char *value);
155 /** Add a new event. The event can be verified in ivi_policy_api::policy_rule_try_event()
159 ivi_policy_add_event(struct ivi_policy *policy, uint32_t state, const char *value);
161 /** Initialize the policy. Not implemented.
163 * Should be implemented by the policy engine. A single policy engine can be used
166 * Returns 0 in case of success, or -1 in case of failure.
169 ivi_policy_init(struct ivi_compositor *ivi);