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);
76 bool (*surface_advertise_state_change)(struct ivi_surface *surf, void *user_data);
78 bool (*shell_bind_interface)(void *client, void *interface);
80 /** see also ivi_policy_add(). If set this will be executed before
81 * adding a new policy rule */
82 bool (*policy_rule_allow_to_add)(void *user_data);
84 /** this callback will be executed when a there's a policy state change */
85 void (*policy_rule_try_event)(struct ivi_a_policy *a_policy);
89 struct ivi_compositor *ivi;
90 /* user-defined hooks */
91 struct ivi_policy_api api;
94 /* represents the policy rules */
95 struct wl_list policies; /* ivi_a_policy::link */
97 /* no state update chnage is being done as long as we have the same
99 uint32_t current_state;
100 uint32_t previous_state;
102 /* guards against current in change in progress */
103 bool state_change_in_progress;
105 /* additional states which can be verified in
106 * ivi_policy_api::policy_rule_try_event() */
107 struct wl_list states; /* state_event::link */
108 struct wl_list events; /* state_event::link */
110 /* necessary to for signaling the state change */
111 struct wl_listener listener_check_policies;
112 struct wl_signal signal_state_change;
116 /** Initialize the policy setup
118 * Policy engine should call ivi_policy_create() with its own ivi_policy_api
122 ivi_policy_create(struct ivi_compositor *compositor,
123 const struct ivi_policy_api *api, void *user_data);
125 /** Destroys the policy setup
129 ivi_policy_destroy(struct ivi_policy *ivi_policy);
131 /** Add a policy rule.
133 * ivi_policy_api::policy_rule_allow_to_add() can be used to limit adding
136 * Returns 0 in case of success, or -1 in case of failure.
140 ivi_policy_add(struct ivi_policy *policy, const char *app_id, uint32_t state,
141 uint32_t event, uint32_t timeout, struct wl_resource *output_res);
143 /** Trigger a state change. This should be called **each time** there is a need
144 * to apply the policy rules.
146 * Returns 0 in case of success, or -1 in case of failure.
149 ivi_policy_state_change(struct ivi_policy *policy, uint32_t state);
152 /** Add a new state. The state can be verified in ivi_policy_api::policy_rule_try_event()
156 ivi_policy_add_state(struct ivi_policy *policy, uint32_t state, const char *value);
158 /** Add a new event. The event can be verified in ivi_policy_api::policy_rule_try_event()
162 ivi_policy_add_event(struct ivi_policy *policy, uint32_t state, const char *value);
164 /** Initialize the policy. Not implemented.
166 * Should be implemented by the policy engine. A single policy engine can be used
169 * Returns 0 in case of success, or -1 in case of failure.
172 ivi_policy_init(struct ivi_compositor *ivi);