2 * Copyright (c) 2021 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.
17 #include <Ecore_Wl2.h>
18 #include <sys/types.h>
21 #include "app-core-ui-cpp/wayland_handler_private.hh"
22 #include "common/log_private.hh"
26 WaylandHandler::WaylandHandler() {
29 WaylandHandler::~WaylandHandler() {
33 int WaylandHandler::Init() {
35 if (__builtin_expect(initialized_, 1))
38 auto* wl2_dsp = ecore_wl2_connected_display_get(nullptr);
39 if (wl2_dsp == nullptr)
40 wl2_dsp = ecore_wl2_display_connect(nullptr);
42 dsp_ = ecore_wl2_display_get(wl2_dsp);
43 if (dsp_ == nullptr) {
44 _E("wl_display_connect() is failed");
48 reg_ = wl_display_get_registry(dsp_);
49 if (reg_ == nullptr) {
50 _E("wl_display_get_registry() is failed");
55 wl_registry_add_listener(reg_, ®_listener_, this);
56 wl_display_roundtrip(dsp_);
58 if (tz_policy_ == nullptr) {
59 _E("Failed to get tizen policy interface");
68 void WaylandHandler::Fini() {
73 tizen_policy_destroy(tz_policy_);
78 wl_registry_destroy(reg_);
86 void WaylandHandler::SetBgState() {
90 tizen_policy_set_background_state(tz_policy_, getpid());
91 wl_display_roundtrip(dsp_);
92 _D("Set Background State");
95 void WaylandHandler::UnsetBgState() {
99 tizen_policy_unset_background_state(tz_policy_, getpid());
100 wl_display_roundtrip(dsp_);
101 _D("Unset Background State");
104 void WaylandHandler::SetAppId(const std::string& app_id) {
108 tizen_policy_set_appid(tz_policy_, getpid(), app_id.c_str());
109 wl_display_roundtrip(dsp_);
110 _D("Set AppId: %s", app_id.c_str());
113 void WaylandHandler::WlListenerCb(void* data, struct wl_registry* reg,
114 uint32_t id, const char* interface, uint32_t ver) {
115 if (interface && !strcmp(interface, "tizen_policy")) {
116 auto* handle = static_cast<WaylandHandler*>(data);
117 if (handle->tz_policy_ == nullptr) {
118 handle->tz_policy_ = reinterpret_cast<struct tizen_policy*>(
119 wl_registry_bind(reinterpret_cast<struct wl_registry*>(handle->reg_),
120 id, &tizen_policy_interface, 7));
125 void WaylandHandler::WlListenerRemoveCb(void* data, struct wl_registry* reg,
129 } // namespace tizen_cpp