policy-default: Install a default policy engine
[src/agl-compositor.git] / src / policy-default.c
1 /*
2  * Copyright © 2020 Collabora, Ltd.
3  *
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:
11  *
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.
15  *
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
23  * SOFTWARE.
24  */
25
26 #include "ivi-compositor.h"
27 #include "policy.h"
28
29 /*
30  * default policy implementation allows every action to be possible
31  *
32  * This is an example, that implements the API
33  *
34  * For injecting rules back in the compositor one should use ivi_policy_add()
35  * - policy_rule_allow_to_add is required in order to add further policy rules
36  * - policy_rule_try_event will be callback executed when handling the state
37  *   change
38  */
39 static bool
40 ivi_policy_default_surface_create(struct ivi_surface *surf, void *user_data)
41 {
42         /* verify that the surface should be created */
43         return true;
44 }
45
46 static bool
47 ivi_policy_default_surface_commmited(struct ivi_surface *surf, void *user_data)
48 {
49         /* verify that the surface should be committed */
50         return true;
51 }
52
53 static bool
54 ivi_policy_default_surface_activate(struct ivi_surface *surf, void *user_data)
55 {
56         /* verify that the surface should be switched to */
57         return true;
58 }
59
60 static bool
61 ivi_policy_default_allow_to_add(void *user_data)
62 {
63         /* verify that policy rules can be added with ivi_policy_add() */
64         return true;
65 }
66
67 /*
68  * Policy rules added by ivi_policy_add() will be handled by this callback, and
69  * should be treated depending on the event. Note this is just an example.
70  */
71 static void
72 ivi_policy_default_try_event(struct ivi_a_policy *a_policy)
73 {
74         uint32_t event = a_policy->event;
75
76         switch (event) {
77         case AGL_SHELL_POLICY_EVENT_SHOW:
78                 ivi_layout_activate(a_policy->output, a_policy->app_id);
79                 break;
80         case AGL_SHELL_POLICY_EVENT_HIDE:
81                 /* FIXME: remove the active one, like basically unmap it? */
82         default:
83                 break;
84         }
85 }
86
87 static const struct ivi_policy_api policy_api = {
88         .struct_size = sizeof(policy_api),
89         .surface_create = ivi_policy_default_surface_create,
90         .surface_commited = ivi_policy_default_surface_commmited,
91         .surface_activate = ivi_policy_default_surface_activate,
92         .policy_rule_allow_to_add = ivi_policy_default_allow_to_add,
93         .policy_rule_try_event = ivi_policy_default_try_event,
94 };
95
96 int
97 ivi_policy_init(struct ivi_compositor *ivi)
98 {
99         ivi->policy = ivi_policy_create(ivi, &policy_api, ivi);
100         if (!ivi->policy)
101                 return -1;
102
103         return 0;
104 }