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.
19 #include <pepper-dali/internal/shell-impl.h>
22 #include <pepper-dali/internal/compositor-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <xdg-shell-server-protocol.h>
40 #if defined(DEBUG_ENABLED)
41 Integration::Log::Filter* gPepperShellLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_SHELL" );
44 static void ClientDestroyed( struct wl_listener* listener, void* data )
46 ShellClientInfo* shellClientInfo = wl_container_of( listener, shellClientInfo, mDestroyListner );
48 shellClientInfo->mShell->OnClientDestroyed( shellClientInfo->mShellClient );
51 } // unnamed namespace
53 ShellPtr Shell::New( Pepper::Compositor compositor )
55 ShellPtr impl = new Shell();
57 // Second-phase init of the implementation
58 impl->Initialize( compositor );
70 mShellClientList.clear();
73 void Shell::Initialize( Pepper::Compositor& compositor )
75 struct wl_display* display;
77 mCompositor = compositor;
79 display = pepper_compositor_get_display( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ) );
81 if( !wl_global_create( display, &xdg_shell_interface, 1, this, Shell::OnBind ) )
83 DALI_LOG_INFO( gPepperShellLogging, Debug::General, "wl_global_create is failed\n" );
86 DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::Initialize: success\n" );
89 void Shell::OnBind( struct wl_client* client, void* data, uint32_t version, uint32_t id )
91 Shell* shell = static_cast< Shell* >( data );
93 Pepper::ShellClient shellClient = Pepper::ShellClient::New( shell->mCompositor, client, version, id );
95 shell->mShellClientList.push_back( shellClient );
97 ShellClientInfo* shellClientInfo = new ShellClientInfo;
99 shellClientInfo->mShell = shell;
100 shellClientInfo->mShellClient = shellClient;
101 shellClientInfo->mDestroyListner.notify = ClientDestroyed;
103 wl_client_add_destroy_listener( client, &shellClientInfo->mDestroyListner );
105 DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::OnBind: success\n" );
108 void Shell::OnClientDestroyed( Pepper::ShellClient shellClient )
110 for ( std::vector< Pepper::ShellClient >::iterator iter = mShellClientList.begin(); mShellClientList.end() != iter; ++iter )
112 if( *iter == shellClient )
114 mShellClientList.erase( iter );
118 DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::OnClientDestroyed: success\n" );
121 } // namespace Internal
123 } // namespace Pepper