2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "tizen-policy.h"
20 #include <dali/integration-api/debug.h>
21 #include <tizen-extension-server-protocol.h>
38 #if defined(DEBUG_ENABLED)
39 Integration::Log::Filter* gPepperTizenPolicyLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_TIZEN_POLICY" );
42 } // unnamed namespace
44 /* tizen policy data for pepper_surface_t */
47 pepper_surface_t *psurf;
48 pepper_event_listener_t *psurf_destroy_listener;
49 struct wl_list resource_list;
50 VisibilityState visibility;
54 const static char *tsurf_data_key = "tzpol-surf";
55 static struct wl_global *_tzpol_global = NULL;
56 static struct wl_list _tzpol_res_list;
59 _tzpol_surface_del(tzpol_surface_t *tsurf)
65 _tzpol_surface_unref(tzpol_surface_t *tsurf, struct wl_resource *unref)
69 res = wl_list_empty(&tsurf->resource_list);
72 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "Couldn't unreference, list is empty" );
76 wl_list_remove(wl_resource_get_link(unref));
77 wl_resource_set_user_data(unref, NULL);
79 res = wl_list_empty(&tsurf->resource_list);
82 pepper_event_listener_remove(tsurf->psurf_destroy_listener);
83 pepper_object_set_user_data((pepper_object_t *)tsurf->psurf,
84 (const void *)tsurf_data_key, NULL, NULL);
85 _tzpol_surface_del(tsurf);
90 _tzpol_surface_ref(tzpol_surface_t *tsurf, struct wl_resource *ref)
92 wl_list_insert(&tsurf->resource_list, wl_resource_get_link(ref));
93 wl_resource_set_user_data(ref, tsurf);
97 _tzpol_surface_pepper_surf_cb_destroy(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
99 tzpol_surface_t *tsurf;
100 struct wl_resource *res, *tmp;
102 tsurf = (tzpol_surface_t*)data;
104 wl_resource_for_each_safe(res, tmp, &tsurf->resource_list)
105 _tzpol_surface_unref(tsurf, res);
108 static tzpol_surface_t *
109 _tzpol_surface_get(pepper_surface_t *psurf)
111 tzpol_surface_t *tsurf;
113 tsurf = (tzpol_surface_t*)pepper_object_get_user_data((pepper_object_t *)psurf,
114 (const void *)tsurf_data_key);
117 tsurf = (tzpol_surface_t*)calloc(1, sizeof(*tsurf));
121 tsurf->psurf = psurf;
123 wl_list_init(&tsurf->resource_list);
125 tsurf->psurf_destroy_listener =
126 pepper_object_add_event_listener((pepper_object_t *)psurf,
127 PEPPER_EVENT_OBJECT_DESTROY, 0,
128 _tzpol_surface_pepper_surf_cb_destroy, tsurf);
129 pepper_object_set_user_data((pepper_object_t *)psurf,
130 (const void *)tsurf_data_key, tsurf, NULL);
138 // --------------------------------------------------------
140 // --------------------------------------------------------
142 _tzvis_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzvis)
144 wl_resource_destroy(res_tzvis);
147 static const struct tizen_visibility_interface _tzvis_iface =
149 _tzvis_iface_cb_destroy
153 _tzvis_res_cb_destroy(struct wl_resource *res_tzvis)
155 tzpol_surface_t *tsurf;
157 tsurf = (tzpol_surface_t*)wl_resource_get_user_data(res_tzvis);
161 _tzpol_surface_unref(tsurf, res_tzvis);
165 _tzpol_iface_cb_vis_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
167 tzpol_surface_t *tsurf;
168 pepper_surface_t *psurf;
169 struct wl_resource *new_res;
174 wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
175 "tizen_policy::visibility_get requires surface");
179 psurf = (pepper_surface_t*)wl_resource_get_user_data(surf);
182 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to get pepper_surface from wl_resource" );
183 wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
184 "tizen_policy::visibility_get invalid surface resource");
188 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::visibility_get" );
189 tsurf = _tzpol_surface_get(psurf);
192 wl_resource_post_no_memory(res_tzpol);
196 ver = wl_resource_get_version(res_tzpol);
197 new_res = wl_resource_create(client, &tizen_visibility_interface, ver, id);
200 wl_resource_post_no_memory(res_tzpol);
204 wl_resource_set_implementation(new_res, &_tzvis_iface, tsurf, _tzvis_res_cb_destroy);
205 _tzpol_surface_ref(tsurf, new_res);
208 // --------------------------------------------------------
210 // --------------------------------------------------------
212 _tzpos_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzpos)
214 wl_resource_destroy(res_tzpos);
218 _tzpos_iface_cb_set(struct wl_client *client, struct wl_resource *res_tzpos, int32_t x, int32_t y)
226 static const struct tizen_position_interface _tzpos_iface =
228 _tzpos_iface_cb_destroy,
233 _tzpos_res_cb_destroy(struct wl_resource *res_tzpos)
235 tzpol_surface_t *tsurf;
237 tsurf = (tzpol_surface_t*)wl_resource_get_user_data(res_tzpos);
241 _tzpol_surface_unref(tsurf, res_tzpos);
245 _tzpol_iface_cb_pos_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
247 tzpol_surface_t *tsurf;
248 pepper_surface_t *psurf;
249 struct wl_resource *new_res;
254 wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
255 "tizen_policy::visibility_get requires surface");
259 psurf = (pepper_surface_t*)wl_resource_get_user_data(surf);
262 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to get pepper_surface from wl_resource" );
263 wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
264 "tizen_policy::visibility_get invalid surface resource");
268 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::visibility_get" );
269 tsurf = _tzpol_surface_get(psurf);
272 wl_resource_post_no_memory(res_tzpol);
276 ver = wl_resource_get_version(res_tzpol);
277 new_res = wl_resource_create(client, &tizen_position_interface, ver, id);
280 wl_resource_post_no_memory(res_tzpol);
284 wl_resource_set_implementation(new_res, &_tzpos_iface, tsurf, _tzpos_res_cb_destroy);
285 _tzpol_surface_ref(tsurf, new_res);
288 // --------------------------------------------------------
289 // stack: activate, raise, lower
290 // --------------------------------------------------------
292 _tzpol_iface_cb_activate(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
300 _tzpol_iface_cb_activate_below_by_res_id(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t res_id, uint32_t below_res_id)
309 _tzpol_iface_cb_raise(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
317 _tzpol_iface_cb_lower(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
325 _tzpol_iface_cb_lower_by_res_id(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t res_id)
332 // --------------------------------------------------------
334 // --------------------------------------------------------
336 _tzpol_iface_cb_focus_skip_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
344 _tzpol_iface_cb_focus_skip_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
351 // --------------------------------------------------------
353 // --------------------------------------------------------
355 _tzpol_iface_cb_role_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, const char *role)
364 _tzpol_iface_cb_type_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t type)
372 // --------------------------------------------------------
374 // --------------------------------------------------------
376 _tzpol_iface_cb_conformant_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
384 _tzpol_iface_cb_conformant_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
392 _tzpol_iface_cb_conformant_get(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
399 // --------------------------------------------------------
400 // notification level
401 // --------------------------------------------------------
403 _tzpol_iface_cb_notilv_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t lv)
411 // --------------------------------------------------------
413 // --------------------------------------------------------
415 _tzpol_iface_cb_transient_for_set(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t child_id, uint32_t parent_id)
424 _tzpol_iface_cb_transient_for_unset(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t child_id)
431 // --------------------------------------------------------
432 // window screen mode
433 // --------------------------------------------------------
435 _tzpol_iface_cb_win_scrmode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
443 // --------------------------------------------------------
445 // --------------------------------------------------------
447 _tzpol_iface_cb_subsurf_place_below_parent(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *subsurf)
455 _tzpol_iface_cb_subsurf_stand_alone_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *subsurf)
463 _tzpol_iface_cb_subsurface_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surface, uint32_t parent_id)
473 _tzpol_iface_cb_opaque_state_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surface, int32_t state)
481 // --------------------------------------------------------
483 // --------------------------------------------------------
485 _tzpol_iface_cb_iconify(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
493 _tzpol_iface_cb_uniconify(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
501 _tzpol_iface_cb_aux_hint_add(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *name, const char *value)
512 _tzpol_iface_cb_aux_hint_change(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *value)
522 _tzpol_iface_cb_aux_hint_del(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id)
531 _tzpol_iface_cb_supported_aux_hints_get(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
539 _tzpol_iface_cb_background_state_set(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t pid)
547 _tzpol_iface_cb_background_state_unset(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t pid)
555 _tzpol_iface_cb_floating_mode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
563 _tzpol_iface_cb_floating_mode_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
571 _tzpol_iface_cb_stack_mode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
579 static const struct tizen_policy_interface _tzpol_iface =
581 _tzpol_iface_cb_vis_get,
582 _tzpol_iface_cb_pos_get,
583 _tzpol_iface_cb_activate,
584 _tzpol_iface_cb_activate_below_by_res_id,
585 _tzpol_iface_cb_raise,
586 _tzpol_iface_cb_lower,
587 _tzpol_iface_cb_lower_by_res_id,
588 _tzpol_iface_cb_focus_skip_set,
589 _tzpol_iface_cb_focus_skip_unset,
590 _tzpol_iface_cb_role_set,
591 _tzpol_iface_cb_type_set,
592 _tzpol_iface_cb_conformant_set,
593 _tzpol_iface_cb_conformant_unset,
594 _tzpol_iface_cb_conformant_get,
595 _tzpol_iface_cb_notilv_set,
596 _tzpol_iface_cb_transient_for_set,
597 _tzpol_iface_cb_transient_for_unset,
598 _tzpol_iface_cb_win_scrmode_set,
599 _tzpol_iface_cb_subsurf_place_below_parent,
600 _tzpol_iface_cb_subsurf_stand_alone_set,
601 _tzpol_iface_cb_subsurface_get,
602 _tzpol_iface_cb_opaque_state_set,
603 _tzpol_iface_cb_iconify,
604 _tzpol_iface_cb_uniconify,
605 _tzpol_iface_cb_aux_hint_add,
606 _tzpol_iface_cb_aux_hint_change,
607 _tzpol_iface_cb_aux_hint_del,
608 _tzpol_iface_cb_supported_aux_hints_get,
609 _tzpol_iface_cb_background_state_set,
610 _tzpol_iface_cb_background_state_unset,
611 _tzpol_iface_cb_floating_mode_set,
612 _tzpol_iface_cb_floating_mode_unset,
613 _tzpol_iface_cb_stack_mode_set,
617 _tzpol_cb_bind(struct wl_client *client, void *data, uint32_t ver, uint32_t id)
619 struct wl_resource *resource;
621 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::bind" );
623 resource = wl_resource_create(client, &tizen_policy_interface, ver, id);
626 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to create resource for tizen_policy" );
627 wl_client_post_no_memory(client);
631 wl_resource_set_implementation(resource, &_tzpol_iface, NULL, NULL);
633 wl_list_insert(&_tzpol_res_list, wl_resource_get_link(resource));
637 TizenPolicyInit(pepper_compositor_t *comp)
639 struct wl_display *wl_disp;
641 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::init" );
646 wl_list_init(&_tzpol_res_list);
648 wl_disp = pepper_compositor_get_display(comp);
649 _tzpol_global = wl_global_create(wl_disp, &tizen_policy_interface, 1, NULL, _tzpol_cb_bind);
652 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to create global for tizen policy" );
660 TizenPolicyShutdown(void)
662 struct wl_resource *res, *tmp;
664 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::shutdown" );
666 wl_resource_for_each_safe(res, tmp, &_tzpol_res_list)
668 wl_list_remove(wl_resource_get_link(res));
669 wl_resource_destroy(res);
672 wl_global_destroy(_tzpol_global);
673 _tzpol_global = NULL;
677 TizenPolicySetVisibility( pepper_surface_t* psurf, VisibilityState state )
679 tzpol_surface_t *tsurf;
680 struct wl_resource *resource;
683 tsurf = (tzpol_surface_t*)pepper_object_get_user_data((pepper_object_t *)psurf, (const void *)tsurf_data_key);
686 DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "there is no data for 'tzpol_surface_t' in 'pepper_surface_t'" );
690 if (tsurf->visibility == state)
693 tsurf->visibility = state;
694 wl_resource_for_each(resource, &tsurf->resource_list)
696 res = wl_resource_instance_of(resource, &tizen_visibility_interface, &_tzvis_iface);
699 tizen_visibility_send_notify(resource, state);
705 } // namespace Extension
707 } // namespace Internal
709 } // namespace Pepper