From 08b81f339305fddb4bcabaf20c9cb29c31bb2abc Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Wed, 29 Jun 2022 10:46:54 +0900 Subject: [PATCH 01/16] devicemgr: use seat_destroy listener in seat_handle_destoy() func. Change-Id: If5556f8ec94836470981691efa5d9d40742f23fa --- src/input-devicemgr/input-devicemgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c index c825b4c..91b7d57 100644 --- a/src/input-devicemgr/input-devicemgr.c +++ b/src/input-devicemgr/input-devicemgr.c @@ -296,7 +296,7 @@ seat_handle_destroy(struct wl_listener *listener, void *data) { struct ds_tizen_input_devicemgr *tz_devicemgr; - tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy); + tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy); wl_list_remove(&tz_devicemgr->seat_destroy.link); wl_list_init(&tz_devicemgr->seat_destroy.link); -- 2.7.4 From a7a4dff1726404c925b393b4244884d5567b2bfb Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 17:36:40 +0900 Subject: [PATCH 02/16] make libds-tizen-backend-tdm change the build script and change tdm.h to tdm_internal.h for libds-tizen-backend-tdm. Change-Id: I7c1db1ae8acdb81bd1ce4fc01edd121782ef1f2d --- examples/meson.build | 9 ++++++++- packaging/libds-tizen.spec | 30 ++++++++++++++++++++++++++++ src/backend/tdm/backend.c | 2 +- src/backend/tdm/meson.build | 33 ++++++++++++++++++++++++------- src/backend/tdm/output.c | 2 +- src/backend/tdm/tdm_buffer_queue.c | 2 +- src/backend/tdm/tdm_buffer_queue.h | 2 +- src/backend/tdm/{tdm.h => tdm_internal.h} | 2 +- src/backend/tdm/tdm_output_hwc.c | 3 ++- src/backend/tdm/tdm_output_hwc.h | 4 +++- src/meson.build | 3 +-- 11 files changed, 75 insertions(+), 17 deletions(-) rename src/backend/tdm/{tdm.h => tdm_internal.h} (98%) diff --git a/examples/meson.build b/examples/meson.build index b7500a1..ca7c6ab 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -5,7 +5,10 @@ common_deps = [ executable('tdm-backend', 'tdm-backend.c', - dependencies: common_deps, + dependencies: [ + common_deps, + dep_libds_tizen_backend_tdm, + ], install_dir: libds_tizen_bindir, install : true ) @@ -21,6 +24,7 @@ executable('tinyds-tdm', tinyds_tdm_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -39,6 +43,7 @@ executable('tinyds-tdm-libinput', tinyds_tdm_libinput_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dep_libds_tizen_input_devicemgr, dependency('pixman-1', required: true), dependency('threads', required: true), @@ -54,6 +59,7 @@ executable('tinyds-tdm-dpms', 'tinyds-tdm-renderer.c', dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -71,6 +77,7 @@ executable('tinyds-tdm-hwc', tinyds_tdm_hwc_files, dependencies: [ common_deps, + dep_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 000f5a9..99b47ae 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -39,6 +39,21 @@ Requires: %{name} = %{version}-%{release} %description devel Development package of Wayland Compositor Library for Tizen +## libds-tizen-backend-tdm +%package backend-tdm +Summary: Display Backend Library with TDM +Group: Development/Libraries + +%description backend-tdm +Display Backend Library with TDM + +%package backend-tdm-devel +Summary: TDM Display Backend Development package +Group: Development/Libraries + +%description backend-tdm-devel +TDM Display Backend Development package + %package keyrouter Summary: Wayland Compositor Library for keyrouter Group: Development/Libraries @@ -106,6 +121,21 @@ ninja -C builddir install %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator +%files backend-tdm +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-backend-tdm.so.* + +%files backend-tdm-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/backend/tdm.h +%{_includedir}/libds-tizen/backend/tdm_output_hwc.h +%{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc +%{_libdir}/libds-tizen-backend-tdm.so + %files keyrouter %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/backend/tdm/backend.c b/src/backend/tdm/backend.c index 2337204..8ca365e 100644 --- a/src/backend/tdm/backend.c +++ b/src/backend/tdm/backend.c @@ -3,7 +3,7 @@ #include -#include "tdm.h" +#include "tdm_internal.h" static const struct ds_backend_interface tdm_backend_iface; diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 7a7c25f..04ecbcf 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -1,14 +1,33 @@ -libds_tizen_files += files( +libds_tizen_backend_tdm_files = files( 'backend.c', 'output.c', 'tdm_buffer_queue.c', 'tdm_output_hwc.c', ) -libtdm = dependency('libtdm', required: true) -libtbm = dependency('libtbm', required: true) - -libds_tizen_deps += [ - libtdm, - libtbm +libds_tizen_backend_tdm_deps = [ + dep_libds_tizen, + dependency('libtdm', required: true), + dependency('libtbm', required: true) ] + +lib_libds_tizen_backend_tdm = shared_library('ds-tizen-backend-tdm', libds_tizen_backend_tdm_files, + dependencies: libds_tizen_backend_tdm_deps, + include_directories: [ include_directories('/usr/include'), common_inc, include_directories('.'), include_directories('..')], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_backend_tdm = declare_dependency( + link_with: lib_libds_tizen_backend_tdm, + dependencies: libds_tizen_backend_tdm_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_backend_tdm, + version: meson.project_version(), + filebase: 'libds-tizen-backend-tdm', + name: 'libds-tizen-backend-tdm', + description: 'tdm backend of libds-tizen for tizen platform', +) \ No newline at end of file diff --git a/src/backend/tdm/output.c b/src/backend/tdm/output.c index 5e874df..c9ad137 100644 --- a/src/backend/tdm/output.c +++ b/src/backend/tdm/output.c @@ -6,7 +6,7 @@ #include #include "libds-tizen/allocator/tbm.h" -#include "tdm.h" +#include "tdm_internal.h" #include "tdm_output_hwc.h" #include "tdm_buffer_queue.h" diff --git a/src/backend/tdm/tdm_buffer_queue.c b/src/backend/tdm/tdm_buffer_queue.c index 3acec8f..40e6353 100644 --- a/src/backend/tdm/tdm_buffer_queue.c +++ b/src/backend/tdm/tdm_buffer_queue.c @@ -6,7 +6,7 @@ #include #include "libds/interfaces/buffer.h" -#include "tdm.h" +#include "tdm_internal.h" #include "tdm_buffer_queue.h" static void diff --git a/src/backend/tdm/tdm_buffer_queue.h b/src/backend/tdm/tdm_buffer_queue.h index a983265..51eab37 100644 --- a/src/backend/tdm/tdm_buffer_queue.h +++ b/src/backend/tdm/tdm_buffer_queue.h @@ -4,7 +4,7 @@ #include #include -#include "tdm.h" +#include "tdm_internal.h" struct ds_tdm_buffer_queue { diff --git a/src/backend/tdm/tdm.h b/src/backend/tdm/tdm_internal.h similarity index 98% rename from src/backend/tdm/tdm.h rename to src/backend/tdm/tdm_internal.h index 7c00202..ef7d88f 100644 --- a/src/backend/tdm/tdm.h +++ b/src/backend/tdm/tdm_internal.h @@ -2,8 +2,8 @@ #define DS_TIZEN_BACKEND_TDM_H #include - #include +#include #include #include diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index 8db2984..48aef1d 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -3,10 +3,11 @@ #include #include -#include #include #include + +#include "tdm_internal.h" #include "tdm_output_hwc.h" static void diff --git a/src/backend/tdm/tdm_output_hwc.h b/src/backend/tdm/tdm_output_hwc.h index 07b3699..bb634d2 100644 --- a/src/backend/tdm/tdm_output_hwc.h +++ b/src/backend/tdm/tdm_output_hwc.h @@ -1,13 +1,15 @@ #ifndef DS_TIZEN_BACKEND_TDM_OUTPUT_HWC_H #define DS_TIZEN_BACKEND_TDM_OUTPUT_HWC_H -#include #include #include #include #include +#include "tdm_internal.h" + + struct ds_tdm_output_hwc_window { struct wl_list link; diff --git a/src/meson.build b/src/meson.build index 1ee9b99..7b61b9a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,7 +34,6 @@ libds_tizen_deps = [ ] subdir('allocator') -subdir('backend') subdir('util') lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, @@ -58,6 +57,6 @@ pkgconfig.generate(lib_libds_tizen, description: 'extension of libds for tizen platform', ) +subdir('backend') subdir('keyrouter') subdir('input-devicemgr') - -- 2.7.4 From 3c94d20bfe406ea2c4ae26609dcd76145e87ef68 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:27:21 +0900 Subject: [PATCH 03/16] make libds-tizen-allocator-tbm change the build script for libds-tizen-allocator-tbm Change-Id: I7dd36d43879e2708f4ead2545849954355f721d2 --- packaging/libds-tizen.spec | 29 +++++++++++++++++++++++++++++ src/allocator/meson.build | 3 +-- src/allocator/tbm/meson.build | 29 +++++++++++++++++++++++++++++ src/allocator/{ => tbm}/tbm.c | 1 - src/backend/tdm/meson.build | 1 + src/backend/tdm/output.c | 3 +-- src/meson.build | 2 +- 7 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 src/allocator/tbm/meson.build rename src/allocator/{ => tbm}/tbm.c (99%) diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 99b47ae..13c2be3 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -39,6 +39,21 @@ Requires: %{name} = %{version}-%{release} %description devel Development package of Wayland Compositor Library for Tizen +## libds-tizen-allocator-tbm +%package allocator-tbm +Summary: Allocator Library with TBM +Group: Development/Libraries + +%description allocator-tbm +Allocator Library with TBM + +%package allocator-tbm-devel +Summary: TBM Allocator Development package +Group: Development/Libraries + +%description allocator-tbm-devel +TBM Allocator Development package + ## libds-tizen-backend-tdm %package backend-tdm Summary: Display Backend Library with TDM @@ -121,6 +136,20 @@ ninja -C builddir install %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator +%files allocator-tbm +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-allocator-tbm.so.* + +%files allocator-tbm-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/allocator/tbm.h +%{_libdir}/pkgconfig/libds-tizen-allocator-tbm.pc +%{_libdir}/libds-tizen-allocator-tbm.so + %files backend-tdm %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/allocator/meson.build b/src/allocator/meson.build index fe869bd..ddc6385 100644 --- a/src/allocator/meson.build +++ b/src/allocator/meson.build @@ -1,2 +1 @@ -libds_tizen_files += files('tbm.c') -libds_tizen_deps += dependency('libtbm', required: true) +subdir('tbm') diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build new file mode 100644 index 0000000..b2ee630 --- /dev/null +++ b/src/allocator/tbm/meson.build @@ -0,0 +1,29 @@ +libds_tizen_allocator_tbm_files = files( + 'tbm.c', +) + +libds_tizen_allocator_tbm_deps = [ + dep_libds_tizen, + dependency('libtbm', required: true) +] + +lib_libds_tizen_allocator_tbm = shared_library('ds-tizen-allocator-tbm', libds_tizen_allocator_tbm_files, + dependencies: libds_tizen_allocator_tbm_deps, + include_directories: [ include_directories('/usr/include'), common_inc, include_directories('.'), include_directories('..')], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_allocator_tbm = declare_dependency( + link_with: lib_libds_tizen_allocator_tbm, + dependencies: libds_tizen_allocator_tbm_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_allocator_tbm, + version: meson.project_version(), + filebase: 'libds-tizen-allocator-tbm', + name: 'libds-tizen-allocator-tbm', + description: 'tbm allocator of libds-tizen for tizen platform', +) \ No newline at end of file diff --git a/src/allocator/tbm.c b/src/allocator/tbm/tbm.c similarity index 99% rename from src/allocator/tbm.c rename to src/allocator/tbm/tbm.c index 0d00793..89591c4 100644 --- a/src/allocator/tbm.c +++ b/src/allocator/tbm/tbm.c @@ -1,7 +1,6 @@ #include #include -#include #include #include #include diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 04ecbcf..7d4102d 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -7,6 +7,7 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ dep_libds_tizen, + dep_libds_tizen_allocator_tbm, dependency('libtdm', required: true), dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/output.c b/src/backend/tdm/output.c index c9ad137..1baefd2 100644 --- a/src/backend/tdm/output.c +++ b/src/backend/tdm/output.c @@ -1,11 +1,10 @@ #include #include - #include #include -#include "libds-tizen/allocator/tbm.h" +#include "libds-tizen/allocator/tbm.h" #include "tdm_internal.h" #include "tdm_output_hwc.h" #include "tdm_buffer_queue.h" diff --git a/src/meson.build b/src/meson.build index 7b61b9a..49dcc09 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,7 +33,6 @@ libds_tizen_deps = [ dependency('tizen-dpms-server', required: true), ] -subdir('allocator') subdir('util') lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, @@ -57,6 +56,7 @@ pkgconfig.generate(lib_libds_tizen, description: 'extension of libds for tizen platform', ) +subdir('allocator') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') -- 2.7.4 From 71b81f381cfb515aa79ee92431d5c29b00bfb109 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:45:23 +0900 Subject: [PATCH 04/16] add comments at spec file Change-Id: Ib6548d595ccc18899ac1be40b485070ff987e951 --- packaging/libds-tizen.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 13c2be3..77774fe 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -69,6 +69,7 @@ Group: Development/Libraries %description backend-tdm-devel TDM Display Backend Development package +## libds-tizen-keyrouter %package keyrouter Summary: Wayland Compositor Library for keyrouter Group: Development/Libraries @@ -83,6 +84,7 @@ Group: Development/Libraries %description keyrouter-devel Keyrouter Development package for Wayland Compositor Library +## libds-tizen-input-devicemgr %package input-devicemgr Summary: Library for tizen input devicemgr Group: Development/Libraries -- 2.7.4 From a105b8f7dca369c08c88c0a8ae4c8e9f102b4200 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 18:50:51 +0900 Subject: [PATCH 05/16] make libds-tizen-dpms change the build script for libds-tizen-dpms Change-Id: I8b0c2827ff715962302807875aee119b04ac8029 --- examples/meson.build | 1 + packaging/libds-tizen.spec | 33 +++++++++++++++++++++++++++++++-- src/{ => dpms}/dpms.c | 0 src/dpms/meson.build | 29 +++++++++++++++++++++++++++++ src/meson.build | 3 +-- 5 files changed, 62 insertions(+), 4 deletions(-) rename src/{ => dpms}/dpms.c (100%) create mode 100644 src/dpms/meson.build diff --git a/examples/meson.build b/examples/meson.build index ca7c6ab..7927407 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -60,6 +60,7 @@ executable('tinyds-tdm-dpms', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_dpms, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 77774fe..4072644 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -99,6 +99,21 @@ Group: Development/Libraries %description input-devicemgr-devel Development package for tizen input devicemgr +## libds-tizen-dpms +%package dpms +Summary: Library for tizen dpms +Group: Development/Libraries + +%description dpms +Library for tizen dpms + +%package dpms-devel +Summary: Development package for tizen dpms +Group: Development/Libraries + +%description dpms-devel +Development package for tizen dpms + %prep %setup -q cp %{SOURCE1001} . @@ -133,8 +148,6 @@ ninja -C builddir install %{_bindir}/tinyds-tdm %{_bindir}/tinyds-tdm-hwc %{_bindir}/ds-simple-tbm -%{_bindir}/tinyds-tdm-dpms -%{_bindir}/ds-simple-dpms %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator @@ -196,3 +209,19 @@ ninja -C builddir install %{_libdir}/libds-tizen-input-devicemgr.so %{_bindir}/tinyds-tdm-libinput %{_bindir}/input-generator + +%files dpms +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-dpms.so.* + +%files dpms-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/dpms.h +%{_libdir}/pkgconfig/libds-tizen-dpms.pc +%{_libdir}/libds-tizen-dpms.so +%{_bindir}/tinyds-tdm-dpms +%{_bindir}/ds-simple-dpms diff --git a/src/dpms.c b/src/dpms/dpms.c similarity index 100% rename from src/dpms.c rename to src/dpms/dpms.c diff --git a/src/dpms/meson.build b/src/dpms/meson.build new file mode 100644 index 0000000..2de950f --- /dev/null +++ b/src/dpms/meson.build @@ -0,0 +1,29 @@ +libds_tizen_dpms_files = [ + 'dpms.c', +] + +libds_tizen_dpms_deps = [ + dep_libds_tizen, + dependency('tizen-dpms-server', required: true), +] + +lib_libds_tizen_dpms = shared_library('ds-tizen-dpms', libds_tizen_dpms_files, + dependencies: libds_tizen_dpms_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_dpms = declare_dependency( + link_with: lib_libds_tizen_dpms, + dependencies: libds_tizen_dpms_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_dpms, + version: meson.project_version(), + filebase: 'libds-tizen-dpms', + name: 'libds-tizen-dpms', + description: 'tizen dpms extension of libds-tizen for tizen platform', +) diff --git a/src/meson.build b/src/meson.build index 49dcc09..538b837 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,6 @@ libds_tizen_files = [ 'pixel_format.c', 'tbm_server.c', - 'dpms.c', ] math = meson.get_compiler('c').find_library('m') @@ -30,7 +29,6 @@ libds_tizen_deps = [ dependency('libdrm', required: true), dependency('libtbm', required: true), dependency('wayland-tbm-server', required: true), - dependency('tizen-dpms-server', required: true), ] subdir('util') @@ -60,3 +58,4 @@ subdir('allocator') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') +subdir('dpms') -- 2.7.4 From e3a8bf20803272a85b98954179ee78e7593e5f17 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 19:16:14 +0900 Subject: [PATCH 06/16] make libds-tizen-tbm-server change the build script for libds-tizen-tbm-server Change-Id: I3bfa4f72ea9298d847f72d1246d0d04f575f162c --- examples/meson.build | 3 ++ examples/tinyds-tdm-dpms.c | 2 +- examples/tinyds-tdm-hwc.c | 2 +- examples/tinyds-tdm-libinput.c | 2 +- examples/tinyds-tdm.c | 2 +- include/libds-tizen/{tbm_server.h => tbm-server.h} | 0 packaging/libds-tizen.spec | 29 ++++++++++++++++++++ src/backend/tdm/meson.build | 1 + src/backend/tdm/tdm_output_hwc.c | 2 +- src/meson.build | 12 ++------ src/tbm-server/meson.build | 32 ++++++++++++++++++++++ src/{ => tbm-server}/pixel_format.c | 0 src/{ => tbm-server}/pixel_format.h | 0 src/{tbm_server.c => tbm-server/tbm-server.c} | 2 +- src/{tbm_server.h => tbm-server/tbm-server.h} | 0 15 files changed, 73 insertions(+), 16 deletions(-) rename include/libds-tizen/{tbm_server.h => tbm-server.h} (100%) create mode 100644 src/tbm-server/meson.build rename src/{ => tbm-server}/pixel_format.c (100%) rename src/{ => tbm-server}/pixel_format.h (100%) rename src/{tbm_server.c => tbm-server/tbm-server.c} (99%) rename src/{tbm_server.h => tbm-server/tbm-server.h} (100%) diff --git a/examples/meson.build b/examples/meson.build index 7927407..56fcd61 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,5 +1,6 @@ common_deps = [ dep_libds_tizen, + dependency('pixman-1', required: true), dependency('wayland-server', required: true), ] @@ -8,6 +9,7 @@ executable('tdm-backend', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_tbm_server, ], install_dir: libds_tizen_bindir, install : true @@ -25,6 +27,7 @@ executable('tinyds-tdm', dependencies: [ common_deps, dep_libds_tizen_backend_tdm, + dep_libds_tizen_tbm_server, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/examples/tinyds-tdm-dpms.c b/examples/tinyds-tdm-dpms.c index dc32e8f..ab34297 100644 --- a/examples/tinyds-tdm-dpms.c +++ b/examples/tinyds-tdm-dpms.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-hwc.c b/examples/tinyds-tdm-hwc.c index 46925f1..762fe07 100644 --- a/examples/tinyds-tdm-hwc.c +++ b/examples/tinyds-tdm-hwc.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-libinput.c b/examples/tinyds-tdm-libinput.c index 3feb932..809f8cf 100644 --- a/examples/tinyds-tdm-libinput.c +++ b/examples/tinyds-tdm-libinput.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/examples/tinyds-tdm.c b/examples/tinyds-tdm.c index 4bc08f1..57b502c 100644 --- a/examples/tinyds-tdm.c +++ b/examples/tinyds-tdm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #define USE_TDM_BUFFER_QUEUE diff --git a/include/libds-tizen/tbm_server.h b/include/libds-tizen/tbm-server.h similarity index 100% rename from include/libds-tizen/tbm_server.h rename to include/libds-tizen/tbm-server.h diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 4072644..cf44015 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -69,6 +69,21 @@ Group: Development/Libraries %description backend-tdm-devel TDM Display Backend Development package +## libds-tizen-tbm-server +%package tbm-server +Summary: Library for wayland-tbm-server +Group: Development/Libraries + +%description tbm-server +Library for tizen input devicemgr + +%package tbm-server-devel +Summary: Development package for wayland-tbm-server +Group: Development/Libraries + +%description tbm-server-devel +Development package for tizen wayland-tbm-server + ## libds-tizen-keyrouter %package keyrouter Summary: Wayland Compositor Library for keyrouter @@ -180,6 +195,20 @@ ninja -C builddir install %{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc %{_libdir}/libds-tizen-backend-tdm.so +%files tbm-server +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-tbm-server.so.* + +%files tbm-server-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/tbm-server.h +%{_libdir}/pkgconfig/libds-tizen-tbm-server.pc +%{_libdir}/libds-tizen-tbm-server.so + %files keyrouter %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 7d4102d..bca5bca 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -8,6 +8,7 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ dep_libds_tizen, dep_libds_tizen_allocator_tbm, + dep_libds_tizen_tbm_server, dependency('libtdm', required: true), dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index 48aef1d..e66b5fa 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "tdm_internal.h" diff --git a/src/meson.build b/src/meson.build index 538b837..7f7447e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,14 +1,10 @@ libds_tizen_files = [ - 'pixel_format.c', - 'tbm_server.c', ] math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) -pixman = dependency('pixman-1', required: true) -libdrm = dependency('libdrm', required: true) -xkbcommon = dependency('xkbcommon', required: true) rt = meson.get_compiler('c').find_library('rt') +xkbcommon = dependency('xkbcommon', required: true) if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') @@ -17,8 +13,6 @@ endif base_deps = [ math, wayland_server, - pixman, - libdrm, xkbcommon, rt, ] @@ -26,9 +20,6 @@ base_deps = [ libds_tizen_deps = [ base_deps, dependency('libds', required: true), - dependency('libdrm', required: true), - dependency('libtbm', required: true), - dependency('wayland-tbm-server', required: true), ] subdir('util') @@ -55,6 +46,7 @@ pkgconfig.generate(lib_libds_tizen, ) subdir('allocator') +subdir('tbm-server') subdir('backend') subdir('keyrouter') subdir('input-devicemgr') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build new file mode 100644 index 0000000..c83ff6c --- /dev/null +++ b/src/tbm-server/meson.build @@ -0,0 +1,32 @@ +libds_tizen_tbm_server_files = [ + 'pixel_format.c', + 'tbm-server.c', +] + +libds_tizen_tbm_server_deps = [ + dep_libds_tizen, + dependency('libdrm', required: true), + dependency('libtbm', required: true), + dependency('wayland-tbm-server', required: true), +] + +lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_tbm_server_files, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +dep_libds_tizen_tbm_server = declare_dependency( + link_with: lib_libds_tizen_tbm_server, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_tbm_server, + version: meson.project_version(), + filebase: 'libds-tizen-tbm-server', + name: 'libds-tizen-tbm-server', + description: 'wayland-tbm extension of libds-tizen for tizen platform', +) diff --git a/src/pixel_format.c b/src/tbm-server/pixel_format.c similarity index 100% rename from src/pixel_format.c rename to src/tbm-server/pixel_format.c diff --git a/src/pixel_format.h b/src/tbm-server/pixel_format.h similarity index 100% rename from src/pixel_format.h rename to src/tbm-server/pixel_format.h diff --git a/src/tbm_server.c b/src/tbm-server/tbm-server.c similarity index 99% rename from src/tbm_server.c rename to src/tbm-server/tbm-server.c index 0fd25cd..9dde248 100644 --- a/src/tbm_server.c +++ b/src/tbm-server/tbm-server.c @@ -6,7 +6,7 @@ #include #include "pixel_format.h" -#include "tbm_server.h" +#include "tbm-server.h" static const struct ds_buffer_resource_interface tbm_buffer_resource_iface; static const struct ds_buffer_interface tbm_client_buffer_iface; diff --git a/src/tbm_server.h b/src/tbm-server/tbm-server.h similarity index 100% rename from src/tbm_server.h rename to src/tbm-server/tbm-server.h -- 2.7.4 From 7c579832443cb0074ea9841775e8564060102878 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:29:41 +0900 Subject: [PATCH 07/16] seperate security to util keyrouter and input-device only depends on security. dpms does not need to depends on security. Change-Id: I84f319dce5d7fb8f8a4c7e1c0d92ce871aeb7986 --- src/input-devicemgr/input-devicemgr.c | 1 + src/input-devicemgr/meson.build | 2 ++ src/keyrouter/keyrouter.c | 1 + src/keyrouter/meson.build | 2 ++ src/meson.build | 11 ++++++++++- src/{util => }/security.c | 0 src/security.h | 15 +++++++++++++++ src/util.h | 15 ++------------- src/util/meson.build | 6 ------ 9 files changed, 33 insertions(+), 20 deletions(-) rename src/{util => }/security.c (100%) create mode 100644 src/security.h delete mode 100644 src/util/meson.build diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c index 91b7d57..b3fc567 100644 --- a/src/input-devicemgr/input-devicemgr.c +++ b/src/input-devicemgr/input-devicemgr.c @@ -9,6 +9,7 @@ #include #include "util.h" +#include "security.h" #include "input-devicemgr.h" #define TIZEN_INPUT_DEVICEMGR_VERSION 4 diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index 7006326..1e69463 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -1,9 +1,11 @@ libds_tizen_input_devicemgr_files = [ + tizen_security_files, 'input-devicemgr.c', ] libds_tizen_input_devicemgr_deps = [ dep_libds_tizen, + deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/keyrouter/keyrouter.c b/src/keyrouter/keyrouter.c index 4bcee93..2e825c6 100644 --- a/src/keyrouter/keyrouter.c +++ b/src/keyrouter/keyrouter.c @@ -8,6 +8,7 @@ #include "libds-tizen/keyrouter.h" #include "util.h" +#include "security.h" #include "keyrouter.h" #define TIZEN_KEYROUTER_VERSION 2 diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index 7c9f01c..af235ce 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -1,10 +1,12 @@ libds_tizen_keyrouter_files = [ + tizen_security_files, 'keyrouter_grab.c', 'keyrouter.c', ] libds_tizen_keyrouter_deps = [ dep_libds_tizen, + deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/meson.build b/src/meson.build index 7f7447e..4d8a290 100644 --- a/src/meson.build +++ b/src/meson.build @@ -22,7 +22,16 @@ libds_tizen_deps = [ dependency('libds', required: true), ] -subdir('util') +tizen_security_files = [ + '../security.c', +] + +deps_tizen_security = [ + base_deps, + dependency('cynara-client', required: true), + dependency('cynara-session', required: true), + dependency('libsmack', required: true) +] lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, dependencies: libds_tizen_deps, diff --git a/src/util/security.c b/src/security.c similarity index 100% rename from src/util/security.c rename to src/security.c diff --git a/src/security.h b/src/security.h new file mode 100644 index 0000000..0c522a0 --- /dev/null +++ b/src/security.h @@ -0,0 +1,15 @@ +#ifndef DS_TIZEN_SECURITY_H +#define DS_TIZEN_SECURITY_H + +#include + +bool +tizen_security_init(void); + +void +tizen_security_finish(void); + +bool +tizen_security_check_privilege(pid_t pid, uid_t uid, const char *privilege); + +#endif diff --git a/src/util.h b/src/util.h index 126467c..425caf3 100644 --- a/src/util.h +++ b/src/util.h @@ -1,17 +1,6 @@ -#ifndef DS_UTIL_H -#define DS_UTIL_H - -#include +#ifndef DS_TIZEN_UTIL_H +#define DS_TIZEN_UTIL_H #define MIN(a,b) ((a)<(b)?(a):(b)) -bool -tizen_security_init(void); - -void -tizen_security_finish(void); - -bool -tizen_security_check_privilege(pid_t pid, uid_t uid, const char *privilege); - #endif diff --git a/src/util/meson.build b/src/util/meson.build deleted file mode 100644 index 0ec6a9d..0000000 --- a/src/util/meson.build +++ /dev/null @@ -1,6 +0,0 @@ -libds_tizen_files += files('security.c') -libds_tizen_deps += [ - dependency('cynara-client', required: true), - dependency('cynara-session', required: true), - dependency('libsmack', required: true) -] -- 2.7.4 From 89860b5de69ab9aa97b832243670aa2fc0955047 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:39:21 +0900 Subject: [PATCH 08/16] Donot make libds-tizen package Remove libds-tizen/libds-tizen-devel packages and libds-tizen library Change-Id: Id66b15da9fe591eb7dc249c7e9faa78205458aae --- examples/meson.build | 2 +- packaging/libds-tizen.spec | 32 ++++---------------------------- src/allocator/tbm/meson.build | 2 +- src/backend/tdm/meson.build | 2 +- src/dpms/meson.build | 2 +- src/input-devicemgr/meson.build | 2 +- src/keyrouter/meson.build | 2 +- src/meson.build | 28 ++-------------------------- src/tbm-server/meson.build | 2 +- tests/meson.build | 2 +- 10 files changed, 14 insertions(+), 62 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 56fcd61..21b6ef9 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,5 +1,5 @@ common_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('pixman-1', required: true), dependency('wayland-server', required: true), ] diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index cf44015..f2702ee 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -31,14 +31,6 @@ BuildRequires: pkgconfig(libsmack) %description Wayland Compositor Library for Tizen -%package devel -Summary: Wayland Compositor Library for Tizen -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -Development package of Wayland Compositor Library for Tizen - ## libds-tizen-allocator-tbm %package allocator-tbm Summary: Allocator Library with TBM @@ -146,26 +138,6 @@ ninja -C builddir all export DESTDIR=%{buildroot} ninja -C builddir install -%files -%manifest %{name}.manifest -%defattr(-,root,root,-) -%license LICENSE -%{_libdir}/libds-tizen.so.* - -%files devel -%manifest %{name}.manifest -%defattr(-,root,root,-) -%license LICENSE -%{_includedir}/libds-tizen/* -%{_libdir}/pkgconfig/libds-tizen.pc -%{_libdir}/libds-tizen.so -%{_bindir}/tdm-backend -%{_bindir}/tinyds-tdm -%{_bindir}/tinyds-tdm-hwc -%{_bindir}/ds-simple-tbm -%{_bindir}/tinyds-tdm-libinput -%{_bindir}/input-generator - %files allocator-tbm %manifest %{name}.manifest %defattr(-,root,root,-) @@ -194,6 +166,10 @@ ninja -C builddir install %{_includedir}/libds-tizen/backend/tdm_output_hwc.h %{_libdir}/pkgconfig/libds-tizen-backend-tdm.pc %{_libdir}/libds-tizen-backend-tdm.so +%{_bindir}/tdm-backend +%{_bindir}/tinyds-tdm +%{_bindir}/tinyds-tdm-hwc +%{_bindir}/ds-simple-tbm %files tbm-server %manifest %{name}.manifest diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build index b2ee630..8a6b882 100644 --- a/src/allocator/tbm/meson.build +++ b/src/allocator/tbm/meson.build @@ -3,7 +3,7 @@ libds_tizen_allocator_tbm_files = files( ) libds_tizen_allocator_tbm_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('libtbm', required: true) ] diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index bca5bca..131a2f3 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -6,7 +6,7 @@ libds_tizen_backend_tdm_files = files( ) libds_tizen_backend_tdm_deps = [ - dep_libds_tizen, + deps_libds_tizen, dep_libds_tizen_allocator_tbm, dep_libds_tizen_tbm_server, dependency('libtdm', required: true), diff --git a/src/dpms/meson.build b/src/dpms/meson.build index 2de950f..61ff9f5 100644 --- a/src/dpms/meson.build +++ b/src/dpms/meson.build @@ -3,7 +3,7 @@ libds_tizen_dpms_files = [ ] libds_tizen_dpms_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('tizen-dpms-server', required: true), ] diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index 1e69463..dcf898c 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -4,7 +4,7 @@ libds_tizen_input_devicemgr_files = [ ] libds_tizen_input_devicemgr_deps = [ - dep_libds_tizen, + deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index af235ce..6f49792 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -5,7 +5,7 @@ libds_tizen_keyrouter_files = [ ] libds_tizen_keyrouter_deps = [ - dep_libds_tizen, + deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), ] diff --git a/src/meson.build b/src/meson.build index 4d8a290..a77f291 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,3 @@ -libds_tizen_files = [ -] - math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) rt = meson.get_compiler('c').find_library('rt') @@ -12,13 +9,13 @@ endif base_deps = [ math, - wayland_server, xkbcommon, rt, ] -libds_tizen_deps = [ +deps_libds_tizen = [ base_deps, + wayland_server, dependency('libds', required: true), ] @@ -33,27 +30,6 @@ deps_tizen_security = [ dependency('libsmack', required: true) ] -lib_libds_tizen = shared_library('ds-tizen', libds_tizen_files, - dependencies: libds_tizen_deps, - include_directories: [ common_inc, include_directories('.') ], - version: meson.project_version(), - install: true -) - -dep_libds_tizen = declare_dependency( - link_with: lib_libds_tizen, - dependencies: libds_tizen_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen, - version: meson.project_version(), - filebase: 'libds-tizen', - name: 'libds-tizen', - description: 'extension of libds for tizen platform', -) - subdir('allocator') subdir('tbm-server') subdir('backend') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build index c83ff6c..25f186e 100644 --- a/src/tbm-server/meson.build +++ b/src/tbm-server/meson.build @@ -4,7 +4,7 @@ libds_tizen_tbm_server_files = [ ] libds_tizen_tbm_server_deps = [ - dep_libds_tizen, + deps_libds_tizen, dependency('libdrm', required: true), dependency('libtbm', required: true), dependency('wayland-tbm-server', required: true), diff --git a/tests/meson.build b/tests/meson.build index 19f1e1d..dae7875 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -12,7 +12,7 @@ tests = [ ] foreach t : tests - t_deps = [ dep_libds_tizen ] + t_deps = [ deps_libds_tizen ] t_deps += t.get('deps', []) test('libds-tizen-' + t.get('name'), -- 2.7.4 From b13ff5ae71c1d8c47ba192f9e3f043928ac7df48 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:40:29 +0900 Subject: [PATCH 09/16] change the var name Change-Id: I9b4cdb7b7d86f4abb05c1e5840aaf9be94d690f1 --- examples/meson.build | 18 +++++++++--------- src/allocator/tbm/meson.build | 2 +- src/backend/tdm/meson.build | 6 +++--- src/dpms/meson.build | 2 +- src/input-devicemgr/meson.build | 2 +- src/keyrouter/meson.build | 2 +- src/tbm-server/meson.build | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 21b6ef9..d9fca10 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -8,8 +8,8 @@ executable('tdm-backend', 'tdm-backend.c', dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_tbm_server, ], install_dir: libds_tizen_bindir, install : true @@ -26,8 +26,8 @@ executable('tinyds-tdm', tinyds_tdm_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_tbm_server, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -46,8 +46,8 @@ executable('tinyds-tdm-libinput', tinyds_tdm_libinput_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_input_devicemgr, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_input_devicemgr, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -62,8 +62,8 @@ executable('tinyds-tdm-dpms', 'tinyds-tdm-renderer.c', dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, - dep_libds_tizen_dpms, + deps_libds_tizen_backend_tdm, + deps_libds_tizen_dpms, dependency('pixman-1', required: true), dependency('threads', required: true), ], @@ -81,7 +81,7 @@ executable('tinyds-tdm-hwc', tinyds_tdm_hwc_files, dependencies: [ common_deps, - dep_libds_tizen_backend_tdm, + deps_libds_tizen_backend_tdm, dependency('pixman-1', required: true), dependency('threads', required: true), ], diff --git a/src/allocator/tbm/meson.build b/src/allocator/tbm/meson.build index 8a6b882..09e16bb 100644 --- a/src/allocator/tbm/meson.build +++ b/src/allocator/tbm/meson.build @@ -14,7 +14,7 @@ lib_libds_tizen_allocator_tbm = shared_library('ds-tizen-allocator-tbm', libds_t install: true ) -dep_libds_tizen_allocator_tbm = declare_dependency( +deps_libds_tizen_allocator_tbm = declare_dependency( link_with: lib_libds_tizen_allocator_tbm, dependencies: libds_tizen_allocator_tbm_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/backend/tdm/meson.build b/src/backend/tdm/meson.build index 131a2f3..359f88d 100644 --- a/src/backend/tdm/meson.build +++ b/src/backend/tdm/meson.build @@ -7,8 +7,8 @@ libds_tizen_backend_tdm_files = files( libds_tizen_backend_tdm_deps = [ deps_libds_tizen, - dep_libds_tizen_allocator_tbm, - dep_libds_tizen_tbm_server, + deps_libds_tizen_allocator_tbm, + deps_libds_tizen_tbm_server, dependency('libtdm', required: true), dependency('libtbm', required: true) ] @@ -20,7 +20,7 @@ lib_libds_tizen_backend_tdm = shared_library('ds-tizen-backend-tdm', libds_tizen install: true ) -dep_libds_tizen_backend_tdm = declare_dependency( +deps_libds_tizen_backend_tdm = declare_dependency( link_with: lib_libds_tizen_backend_tdm, dependencies: libds_tizen_backend_tdm_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/dpms/meson.build b/src/dpms/meson.build index 61ff9f5..e752c68 100644 --- a/src/dpms/meson.build +++ b/src/dpms/meson.build @@ -14,7 +14,7 @@ lib_libds_tizen_dpms = shared_library('ds-tizen-dpms', libds_tizen_dpms_files, install: true ) -dep_libds_tizen_dpms = declare_dependency( +deps_libds_tizen_dpms = declare_dependency( link_with: lib_libds_tizen_dpms, dependencies: libds_tizen_dpms_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index dcf898c..f84f542 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -16,7 +16,7 @@ lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', lib install: true ) -dep_libds_tizen_input_devicemgr = declare_dependency( +deps_libds_tizen_input_devicemgr = declare_dependency( link_with: lib_libds_tizen_input_devicemgr, dependencies: libds_tizen_input_devicemgr_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/keyrouter/meson.build b/src/keyrouter/meson.build index 6f49792..db1fec9 100644 --- a/src/keyrouter/meson.build +++ b/src/keyrouter/meson.build @@ -20,7 +20,7 @@ lib_libds_tizen_keyrouter = shared_library('ds-tizen-keyrouter', libds_tizen_key install: true ) -dep_libds_tizen_keyrouter = declare_dependency( +deps_libds_tizen_keyrouter = declare_dependency( link_with: lib_libds_tizen_keyrouter, dependencies: libds_tizen_keyrouter_deps, include_directories: [ common_inc, include_directories('.') ], diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build index 25f186e..ced06a4 100644 --- a/src/tbm-server/meson.build +++ b/src/tbm-server/meson.build @@ -17,7 +17,7 @@ lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_t install: true ) -dep_libds_tizen_tbm_server = declare_dependency( +deps_libds_tizen_tbm_server = declare_dependency( link_with: lib_libds_tizen_tbm_server, dependencies: libds_tizen_tbm_server_deps, include_directories: [ common_inc, include_directories('.') ], -- 2.7.4 From 60ffc8f415be010523435d85ac55613916ff69fa Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:47:07 +0900 Subject: [PATCH 10/16] remove xkbcommon from base_dep Change-Id: I43f6bea638488d1c066a984ee1623285405e8f58 --- src/input-devicemgr/meson.build | 1 + src/meson.build | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build index f84f542..4616f6f 100644 --- a/src/input-devicemgr/meson.build +++ b/src/input-devicemgr/meson.build @@ -7,6 +7,7 @@ libds_tizen_input_devicemgr_deps = [ deps_libds_tizen, deps_tizen_security, dependency('tizen-extension-server', required: true), + dependency('xkbcommon', required: true), ] lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', libds_tizen_input_devicemgr_files, diff --git a/src/meson.build b/src/meson.build index a77f291..64f5d1f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,6 @@ math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) rt = meson.get_compiler('c').find_library('rt') -xkbcommon = dependency('xkbcommon', required: true) if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') @@ -9,7 +8,6 @@ endif base_deps = [ math, - xkbcommon, rt, ] -- 2.7.4 From 706e87bb9aa05678a0a0d664587c0148cde8feb6 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 30 Jun 2022 09:48:07 +0900 Subject: [PATCH 11/16] change the name of base_deps into deps_base Change-Id: Ifb6fe3f03cc1d8d9e86341f54c000f7f03f9f1ef --- src/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/meson.build b/src/meson.build index 64f5d1f..b4b92f5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,13 +6,13 @@ if wayland_server.version().version_compare('>= 1.19') cdata.set('HAVE_WL_SEAT_ERROR_MISSING_CAPABILITY', '1') endif -base_deps = [ +deps_base = [ math, rt, ] deps_libds_tizen = [ - base_deps, + deps_base, wayland_server, dependency('libds', required: true), ] @@ -22,7 +22,6 @@ tizen_security_files = [ ] deps_tizen_security = [ - base_deps, dependency('cynara-client', required: true), dependency('cynara-session', required: true), dependency('libsmack', required: true) -- 2.7.4 From 60ea1f4373e6ceb6eb99ef2dd7699a7468a098e0 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 4 Jul 2022 19:23:19 +0900 Subject: [PATCH 12/16] change file names and folder names use the underbar instead of a hyphen when you name files and folders. Change-Id: I72c903fef3f5e2dc4fbc4df09524b7215c211685 --- examples/tinyds-tdm-dpms.c | 2 +- examples/tinyds-tdm-hwc.c | 2 +- examples/tinyds-tdm-libinput.c | 4 +- examples/tinyds-tdm.c | 2 +- include/libds-tizen/input-devicemgr.h | 44 - include/libds-tizen/tbm-server.h | 33 - packaging/libds-tizen.spec | 4 +- src/backend/tdm/tdm_output_hwc.c | 2 +- src/input-devicemgr/input-devicemgr.c | 1551 --------------------------------- src/input-devicemgr/input-devicemgr.h | 78 -- src/input-devicemgr/meson.build | 32 - src/meson.build | 4 +- src/tbm-server/meson.build | 32 - src/tbm-server/pixel_format.c | 61 -- src/tbm-server/pixel_format.h | 10 - src/tbm-server/tbm-server.c | 268 ------ src/tbm-server/tbm-server.h | 34 - tests/meson.build | 8 +- tests/test-backend.c | 80 -- tests/test-compositor.c | 63 -- tests/test-subsurface.c | 211 ----- tests/test-surface.c | 162 ---- 22 files changed, 14 insertions(+), 2673 deletions(-) delete mode 100644 include/libds-tizen/input-devicemgr.h delete mode 100644 include/libds-tizen/tbm-server.h delete mode 100644 src/input-devicemgr/input-devicemgr.c delete mode 100644 src/input-devicemgr/input-devicemgr.h delete mode 100644 src/input-devicemgr/meson.build delete mode 100644 src/tbm-server/meson.build delete mode 100644 src/tbm-server/pixel_format.c delete mode 100644 src/tbm-server/pixel_format.h delete mode 100644 src/tbm-server/tbm-server.c delete mode 100644 src/tbm-server/tbm-server.h delete mode 100644 tests/test-backend.c delete mode 100644 tests/test-compositor.c delete mode 100644 tests/test-subsurface.c delete mode 100644 tests/test-surface.c diff --git a/examples/tinyds-tdm-dpms.c b/examples/tinyds-tdm-dpms.c index ab34297..dc32e8f 100644 --- a/examples/tinyds-tdm-dpms.c +++ b/examples/tinyds-tdm-dpms.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-hwc.c b/examples/tinyds-tdm-hwc.c index 762fe07..46925f1 100644 --- a/examples/tinyds-tdm-hwc.c +++ b/examples/tinyds-tdm-hwc.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define USE_TDM_BUFFER_QUEUE diff --git a/examples/tinyds-tdm-libinput.c b/examples/tinyds-tdm-libinput.c index 809f8cf..b1974f1 100644 --- a/examples/tinyds-tdm-libinput.c +++ b/examples/tinyds-tdm-libinput.c @@ -16,14 +16,14 @@ #include #include #include -#include +#include #include #include #include #include #include -#include +#include #include #include diff --git a/examples/tinyds-tdm.c b/examples/tinyds-tdm.c index 57b502c..4bc08f1 100644 --- a/examples/tinyds-tdm.c +++ b/examples/tinyds-tdm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #define USE_TDM_BUFFER_QUEUE diff --git a/include/libds-tizen/input-devicemgr.h b/include/libds-tizen/input-devicemgr.h deleted file mode 100644 index fc1060e..0000000 --- a/include/libds-tizen/input-devicemgr.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef LIBDS_TIZEN_INPUT_DEVICEMGR_H -#define LIBDS_TIZEN_INPUT_DEVICEMGR_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ds_tizen_input_devicemgr; -struct ds_backend; -struct ds_seat; - -struct ds_tizen_input_devicemgr_keymap_data -{ - char *name; - int keycode; - - struct wl_list link; -}; - -struct ds_tizen_input_devicemgr * -ds_tizen_input_devicemgr_create(struct ds_backend *backend, - struct ds_seat *seat); - -void -ds_tizen_input_devicemgr_add_destroy_listener( - struct ds_tizen_input_devicemgr *devicemgr, - struct wl_listener *listener); - -bool -ds_tizen_input_devicemgr_set_keymap_list( - struct ds_tizen_input_devicemgr *devicemgr, - struct wl_list *list); - -bool -ds_tizen_input_devicemgr_set_output_width_height( - struct ds_tizen_input_devicemgr *devicemgr, - uint32_t width, uint32_t height); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/libds-tizen/tbm-server.h b/include/libds-tizen/tbm-server.h deleted file mode 100644 index 6e3b148..0000000 --- a/include/libds-tizen/tbm-server.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef LIBDS_TIZEN_TBM_SERVER_H -#define LIBDS_TIZEN_TBM_SERVER_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ds_tbm_server; - -struct ds_tbm_client_buffer; - -struct ds_tbm_server * -ds_tbm_server_create(struct wl_display *display); - -void -ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, - struct wl_listener *listener); - -struct ds_tbm_client_buffer * -ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer); - -tbm_surface_h -ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index f2702ee..fe34941 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -181,7 +181,7 @@ ninja -C builddir install %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_includedir}/libds-tizen/tbm-server.h +%{_includedir}/libds-tizen/tbm_server.h %{_libdir}/pkgconfig/libds-tizen-tbm-server.pc %{_libdir}/libds-tizen-tbm-server.so @@ -209,7 +209,7 @@ ninja -C builddir install %manifest %{name}.manifest %defattr(-,root,root,-) %license LICENSE -%{_includedir}/libds-tizen/input-devicemgr.h +%{_includedir}/libds-tizen/input_devicemgr.h %{_libdir}/pkgconfig/libds-tizen-input-devicemgr.pc %{_libdir}/libds-tizen-input-devicemgr.so %{_bindir}/tinyds-tdm-libinput diff --git a/src/backend/tdm/tdm_output_hwc.c b/src/backend/tdm/tdm_output_hwc.c index e66b5fa..48aef1d 100644 --- a/src/backend/tdm/tdm_output_hwc.c +++ b/src/backend/tdm/tdm_output_hwc.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "tdm_internal.h" diff --git a/src/input-devicemgr/input-devicemgr.c b/src/input-devicemgr/input-devicemgr.c deleted file mode 100644 index b3fc567..0000000 --- a/src/input-devicemgr/input-devicemgr.c +++ /dev/null @@ -1,1551 +0,0 @@ -#include -#include // gettimeofday() -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "security.h" -#include "input-devicemgr.h" - -#define TIZEN_INPUT_DEVICEMGR_VERSION 4 -#define TIZEN_PRIV_INPUT_GENERATOR "http://tizen.org/privilege/inputgenerator" -#define TIZEN_PRIV_INPUT_BLOCK "http://tizen.org/privilege/internal/inputdevice.block" -#define TIZEN_INPUT_DEVICEMGR_MAX_BTN 16 - -static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface; - -//listeners -static void -backend_handle_destroy(struct wl_listener *listener, void *data); -static void -backend_handle_input_device_add(struct wl_listener *listener, void *data); -static void -seat_handle_destroy(struct wl_listener *listener, void *data); - -//tizen_input_device_manager bind/unbind -static void -device_manager_handle_bind(struct wl_client *client, void *data, - uint32_t version, uint32_t id); -static void -device_manager_client_handle_resource_destroy(struct wl_resource *resource); - -//tizen_input_device_manager's handlers for requests -static void -device_manager_handle_block_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial, - uint32_t clas, uint32_t duration); -static void -device_manager_handle_unblock_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial); -static void -device_manager_handle_init_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas); -static void -device_manager_handle_init_generator_with_name(struct wl_client *client, - struct wl_resource *resource, uint32_t clas, const char *name); -static void -device_manager_handle_deinit_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas); -static void -device_manager_handle_generate_key(struct wl_client *client, - struct wl_resource *resource, - const char *keyname, uint32_t pressed); -static void -device_manager_handle_generate_touch(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t finger); -static void -device_manager_handle_generate_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t button); -static void -device_manager_handle_destroy(struct wl_client *client, - struct wl_resource *resource); - -// -static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr); -static int -tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, uint32_t clas, const char *name); -static int -tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource); -static bool -tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, - int pressed); -static bool -tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, - int keycode, bool pressed); -static void -tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); -static int -tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name); - -static bool -tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, - uint32_t finger); -static bool -tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, - uint32_t finger); -static bool -tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger); -static bool -tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y); -static bool -tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state); - -static bool -tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_client *client, const char *rule); - -static void -tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr); -static void -tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); - -WL_EXPORT struct ds_tizen_input_devicemgr * -ds_tizen_input_devicemgr_create(struct ds_backend *backend, - struct ds_seat *seat) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = calloc(1, sizeof *tz_devicemgr); - if (!tz_devicemgr) { - ds_err("Fail to allocate ds_tizen_input_devicemgr"); - return NULL; - } - - tz_devicemgr->backend = backend; - tz_devicemgr->backend_destroy.notify = backend_handle_destroy; - ds_backend_add_destroy_listener(backend, &tz_devicemgr->backend_destroy); - - tz_devicemgr->seat = seat; - tz_devicemgr->seat_destroy.notify = seat_handle_destroy; - ds_seat_add_destroy_listener(seat, &tz_devicemgr->seat_destroy); - - tz_devicemgr->new_input.notify = backend_handle_input_device_add; - ds_backend_add_new_input_listener(backend, &tz_devicemgr->new_input); - - tz_devicemgr->global = wl_global_create(backend->display, - &tizen_input_device_manager_interface, - TIZEN_INPUT_DEVICEMGR_VERSION, - tz_devicemgr, device_manager_handle_bind); - if (!tz_devicemgr->global) { - goto err_global; - } - - tz_devicemgr->devices.kbd = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.kbd) { - goto err_kbd; - } - tz_devicemgr->devices.ptr = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.ptr) { - goto err_ptr; - } - tz_devicemgr->devices.touch = calloc(1, - sizeof(struct ds_tizen_input_devicemgr_device)); - if (!tz_devicemgr->devices.touch) { - goto err_touch; - } - tz_devicemgr->touch_max_count = 5;//TODO: make this variable configurable - - tz_devicemgr->grab = ds_seat_create_keyboard_grab( - tz_devicemgr->seat, &devicemgr_keyboard_grab_iface, tz_devicemgr); - if (!tz_devicemgr->grab) { - goto err_grab; - } - - wl_signal_init(&tz_devicemgr->events.destroy); - wl_list_init(&tz_devicemgr->clients); - wl_list_init(&tz_devicemgr->devices.kbd->key.pressed); - wl_list_init(&tz_devicemgr->keymap_list); - wl_list_init(&tz_devicemgr->blocked_keys); - - if (!tizen_security_init()) { - ds_inf("tizen_security_init() is failed. go on without security"); - } - - ds_inf("Global created: ds_tizen_input_devicemgr(%p) ", tz_devicemgr); - return tz_devicemgr; - -err_grab: - free(tz_devicemgr->devices.touch); -err_touch: - free(tz_devicemgr->devices.ptr); -err_ptr: - free(tz_devicemgr->devices.kbd); -err_kbd: - wl_global_destroy(tz_devicemgr->global); -err_global: - wl_list_remove(&tz_devicemgr->backend_destroy.link); - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_remove(&tz_devicemgr->new_input.link); - free(tz_devicemgr); - return NULL; -} - -WL_EXPORT void -ds_tizen_input_devicemgr_add_destroy_listener( - struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_listener *listener) -{ - wl_signal_add(&tz_devicemgr->events.destroy, listener); -} - -WL_EXPORT bool -ds_tizen_input_devicemgr_set_keymap_list( - struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_list *list) -{ - struct ds_tizen_input_devicemgr_keymap_data *data, *new_data; - - if (!tz_devicemgr || !list) { - ds_err("Please insert correct data\n"); - return false; - } - - wl_list_for_each(data, list, link) { - new_data = calloc(1, sizeof *data); - if (!new_data) { - ds_err("Failed to alloc memory"); - return false; - } - new_data->name = strdup(data->name); - new_data->keycode = data->keycode; - wl_list_insert(&tz_devicemgr->keymap_list, &new_data->link); - } - ds_inf("keymap set. length:%d", - wl_list_length(&tz_devicemgr->keymap_list)); - - return true; -} - -WL_EXPORT bool -ds_tizen_input_devicemgr_set_output_width_height( - struct ds_tizen_input_devicemgr *tz_devicemgr, - uint32_t width, uint32_t height) -{ - if (!tz_devicemgr) return false; - - tz_devicemgr->output.width = width; - tz_devicemgr->output.height = height; - - ds_inf("output's width: %d, height:%d", width, height); - - return true; -} - -static void -tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_client *client_data, *tmp; - - tizen_security_finish(); - - tz_devicemgr_keymap_list_cleanup(tz_devicemgr); - tz_devicemgr_blocked_keys_cleanup(tz_devicemgr); - tz_devicemgr_ungrab_keyboard(tz_devicemgr); - ds_seat_keyboard_destroy_grab(tz_devicemgr->grab); - - wl_signal_emit(&tz_devicemgr->events.destroy, tz_devicemgr); - wl_list_remove(&tz_devicemgr->backend_destroy.link); - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_remove(&tz_devicemgr->new_input.link); - - wl_global_destroy(tz_devicemgr->global); - - wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { - wl_list_remove(&client_data->link); - tz_devicemgr_deinit_generator(tz_devicemgr, client_data->resource); - - wl_resource_set_user_data(client_data->resource, NULL); - free(client_data); - } - - free(tz_devicemgr->devices.touch); - free(tz_devicemgr->devices.ptr); - free(tz_devicemgr->devices.kbd); - free(tz_devicemgr); -} - -static void -backend_handle_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy); - - ds_inf("Global destroy: ds_tizen_input_devicemgr(%p)", tz_devicemgr); - - tz_devicemgr_destroy(tz_devicemgr); -} - -static void -seat_handle_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy); - - wl_list_remove(&tz_devicemgr->seat_destroy.link); - wl_list_init(&tz_devicemgr->seat_destroy.link); - tz_devicemgr->seat = NULL; -} - -static void -tz_devicemgr_device_close(struct ds_tizen_input_devicemgr_device *dev) -{ - if (!dev->input_device) return; - ds_input_device_destroy(dev->input_device); - dev->input_device = NULL; -} - -static void -backend_handle_input_device_add(struct wl_listener *listener, void *data) -{ - struct ds_input_device *dev = data; - struct ds_tizen_input_devicemgr *tz_devicemgr; - enum ds_input_device_type dev_type; - - tz_devicemgr = wl_container_of(listener, tz_devicemgr, new_input); - - dev_type = ds_input_device_get_type(dev); - if (dev_type == DS_INPUT_DEVICE_KEYBOARD) { - if (tz_devicemgr->devices.kbd->input_device) return; - ds_inf("devicemgr's kbd device is set to dev(%p)", dev); - tz_devicemgr->devices.kbd->input_device = dev; - } - else if (dev_type == DS_INPUT_DEVICE_POINTER) { - if (tz_devicemgr->devices.ptr->input_device) return; - ds_inf("devicemgr's ptr device is set to dev(%p)", dev); - tz_devicemgr->devices.ptr->input_device = dev; - } - else if (dev_type == DS_INPUT_DEVICE_TOUCH) { - if (tz_devicemgr->devices.touch->input_device) return; - ds_inf("devicemgr's touch device is set to dev(%p)", dev); - tz_devicemgr->devices.touch->input_device = dev; - } -} - -static const struct tizen_input_device_manager_interface _devicemgr_impl = { - .block_events = device_manager_handle_block_events, - .unblock_events = device_manager_handle_unblock_events, - .init_generator = device_manager_handle_init_generator, - .deinit_generator = device_manager_handle_deinit_generator, - .generate_key = device_manager_handle_generate_key, - .generate_pointer = device_manager_handle_generate_pointer, - .generate_touch = device_manager_handle_generate_touch, - .pointer_warp = NULL, - .init_generator_with_name = - device_manager_handle_init_generator_with_name, // v2 - .destroy = device_manager_handle_destroy, // v3 - .generate_axis = NULL, // v3 - .set_touch_count = NULL, // v4 -}; - -static void -device_manager_client_handle_resource_destroy(struct wl_resource *resource) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - struct ds_tizen_input_devicemgr_client *client_data, *tmp; - - tz_devicemgr = wl_resource_get_user_data(resource); - - tz_devicemgr_deinit_generator(tz_devicemgr, resource); - - if (resource == tz_devicemgr->block_resource) { - tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); - if (tz_devicemgr->timer) { - wl_event_source_remove(tz_devicemgr->timer); - tz_devicemgr->timer = NULL; - } - } - - wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - wl_list_remove(&client_data->link); - free(client_data); - } - } -} - -static void -device_manager_handle_bind(struct wl_client *client, void *data, - uint32_t version, uint32_t id) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr = data; - struct ds_tizen_input_devicemgr_client *client_data; - - client_data = calloc(1, sizeof *client_data); - if (!client_data) { - ds_err("Failed to allocate memory !\n"); - wl_client_post_no_memory(client); - return; - } - - client_data->resource = wl_resource_create(client, - &tizen_input_device_manager_interface, MIN(version,4), id); - if (!client_data->resource) { - ds_err("Failed to create resource! (ver. :%d, id:%d)", version, id); - free(client_data); - wl_client_post_no_memory(client); - return; - } - - client_data->init = false; - wl_list_init(&client_data->link); - wl_list_insert(&tz_devicemgr->clients, &client_data->link); - - wl_resource_set_implementation(client_data->resource, &_devicemgr_impl, - tz_devicemgr, device_manager_client_handle_resource_destroy); -} - -static void -device_manager_handle_init_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, - "Input Generator"); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to init input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_init_generator_with_name(struct wl_client *client, - struct wl_resource *resource, uint32_t clas, const char *name) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!name) { - ds_err("no name for device"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, - name); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to init input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_deinit_generator(struct wl_client *client, - struct wl_resource *resource, uint32_t clas __attribute__((unused))) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - ret = tz_devicemgr_deinit_generator(tz_devicemgr, resource); - if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - ds_err("Failed to deinit input generator\n"); - goto finish; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -struct keycode_map{ - xkb_keysym_t keysym; - xkb_keycode_t keycode; -}; - -static void -find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) -{ - struct keycode_map *found_keycodes = (struct keycode_map *)data; - xkb_keysym_t keysym = found_keycodes->keysym; - int nsyms = 0; - const xkb_keysym_t *syms_out = NULL; - - if (found_keycodes->keycode) return; - - nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out); - if (nsyms && syms_out) { - if (*syms_out == keysym) { - found_keycodes->keycode = key; - } - } -} - -static void -tz_devicemgr_xkb_keycode_from_keysym(struct xkb_keymap *keymap, - xkb_keysym_t keysym, xkb_keycode_t *keycode) -{ - struct keycode_map found_keycodes = {0,}; - found_keycodes.keysym = keysym; - xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes); - - *keycode = found_keycodes.keycode; -} - -static int -tz_devicemgr_xkb_keyname_to_keycode(struct xkb_keymap *keymap, - const char *name) -{ - xkb_keysym_t keysym = 0x0; - xkb_keycode_t keycode = 0; - - if (!strncmp(name, "Keycode-", sizeof("Keycode-")-1)) { - keycode = atoi(name + 8); - } else { - keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS); - tz_devicemgr_xkb_keycode_from_keysym(keymap, keysym, &keycode); - } - - return keycode; -} - -static uint32_t -tz_devicemgr_client_get_device_clas(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource) -{ - struct ds_tizen_input_devicemgr_client *client_data; - - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) - return client_data->clas; - } - return 0; -} - -static void -device_manager_handle_generate_key(struct wl_client *client, - struct wl_resource *resource, const char *keyname, uint32_t pressed) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - int keycode = 0; - bool res; - struct ds_keyboard *kbd; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) == 0) - { - ds_err("Keyboard generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.kbd || - !tz_devicemgr->devices.kbd->input_device) { - ds_err("Keyboard device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - // keyname to keycode using xkb_info - kbd = ds_input_device_get_keyboard( - tz_devicemgr->devices.kbd->input_device); - if (kbd->keymap) { - keycode = tz_devicemgr_xkb_keyname_to_keycode(kbd->keymap, keyname); - } - - if (keycode <= 0) { - keycode = tz_devicemgr_keyname_to_keycode(&tz_devicemgr->keymap_list, - keyname); - } - if (keycode <= 0) - goto finish; - - res = tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, - keycode, pressed); - if (!res) { - ds_err("Generating key is failed. key: %s, pressed: %d", - keyname, pressed); - goto finish; - } - res = tz_devicemgr_pressed_keys_update(tz_devicemgr, keycode, pressed); - if (!res) { - ds_err("Updating pressed keys is failed. key: %s, pressed: %d", - keyname, pressed); - goto finish; - } - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_generate_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t button) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - bool state; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) == 0) - { - ds_err("Pointer generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.ptr || - !tz_devicemgr->devices.ptr->input_device) { - ds_err("Pointer device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (button <= 0 || button >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) - { - ds_err("Invalid button: %d\n", button); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE) { - res = tz_devicemgr_generate_mouse_move( - tz_devicemgr->devices.ptr->input_device, (double)x, (double)y); - if (!res) goto finish; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - else { - state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ? - true : false; - res = tz_devicemgr_generate_mouse_button( - tz_devicemgr->devices.ptr->input_device, button, state); - if (!res) goto finish; - if (state) tz_devicemgr->devices.ptr->mouse.pressed |= 1 << (button - 1); - else tz_devicemgr->devices.ptr->mouse.pressed &= ~(1 << (button - 1)); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_generate_touch(struct wl_client *client, - struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, - uint32_t finger) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - double transformed_x = .0, transformed_y = .0; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - uint32_t clas; - - tz_devicemgr = wl_resource_get_user_data(resource); - - clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); - if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) == 0) - { - ds_err("Touch generator is not initialized by client"); - goto finish; - } - - if (!tz_devicemgr->devices.touch || - !tz_devicemgr->devices.touch->input_device) { - ds_err("Touch device is not initialized\n"); - goto finish; - } - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_GENERATOR)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (finger >= tz_devicemgr->touch_max_count) - { - ds_err("Invalid fingers: %d\n", finger); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) { - transformed_x = x / (double)tz_devicemgr->output.width; - transformed_y = y / (double)tz_devicemgr->output.height; - } - - switch(type) { - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: // 0 - res = tz_devicemgr_generate_touch_move( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - res= tz_devicemgr_generate_touch_down( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - tz_devicemgr->devices.touch->touch.pressed |= 1 << finger; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END: // 2 - res = tz_devicemgr_generate_touch_up( - tz_devicemgr->devices.touch->input_device, finger); - if (!res) break; - tz_devicemgr->devices.touch->touch.pressed &= ~(1 << finger); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE: // 1 - res = tz_devicemgr_generate_touch_move( - tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); - if (!res) break; - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - break; - default: - break; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_destroy(struct wl_client *client, - struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static bool -tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_client *client, const char *rule) -{ - pid_t pid = 0; - uid_t uid = 0; - gid_t gid = 0; - - if (!client) return false; - - wl_client_get_credentials(client, &pid, &uid, &gid); - - return tizen_security_check_privilege(pid, uid, rule); -} - -static const struct ds_input_device_interface input_device_iface = -{ - .destroy = NULL, -}; - -static struct ds_keyboard * -create_ds_keyboard() -{ - struct ds_keyboard *kbd; - kbd = calloc(1, sizeof *kbd); - if (!kbd) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_keyboard_init(kbd, NULL); - - return kbd; -} - -static struct ds_pointer * -create_ds_pointer() -{ - struct ds_pointer *pointer; - pointer = calloc(1, sizeof *pointer); - if (!pointer) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_pointer_init(pointer, NULL); - - return pointer; -} - -static struct ds_touch * -create_ds_touch() -{ - struct ds_touch *touch; - touch = calloc(1, sizeof *touch); - if (!touch) { - ds_err("Could not allocate memory"); - return NULL; - } - ds_touch_init(touch, NULL); - - return touch; -} - -static int -tz_devicemgr_create_device(struct ds_tizen_input_devicemgr_device *dev, - uint32_t clas, const char *name) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - const char *dev_name; - - if (dev->name && strlen(dev->name) > 0) { - ds_inf("device already has name. name:%s", dev->name); - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - - if (dev->input_device) { - dev_name = ds_input_device_get_name(dev->input_device); - ds_inf("device was already set. name:%s", dev_name); - dev->name = strdup(dev_name); - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - } - - //input_device create - dev->input_device = calloc(1, sizeof(struct ds_input_device)); - if(!dev->input_device) { - ds_err("Failed to create input device !\n"); - return ret; - } - - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_KEYBOARD, - &input_device_iface, name, -1, -1); - dev->input_device->keyboard = create_ds_keyboard(); - } - else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_POINTER, - &input_device_iface, name, -1, -1); - dev->input_device->pointer = create_ds_pointer(); - } - else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) - { - ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_TOUCH, - &input_device_iface, name, -1, -1); - dev->input_device->touch = create_ds_touch(); - } - - dev->created = true; - dev->name = strdup(name); - - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; -} - -static int -tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource, uint32_t clas, const char *name) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - struct ds_tizen_input_devicemgr_client *client_data; - struct ds_tizen_input_devicemgr_device *dev; - bool inited = false; - - ds_inf("Init generator. name:%s", name); - - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - dev = tz_devicemgr->devices.kbd; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.kbd->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { - dev = tz_devicemgr->devices.ptr; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.ptr->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { - dev = tz_devicemgr->devices.touch; - ret = tz_devicemgr_create_device(dev, clas, name); - if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { - inited = true; - tz_devicemgr->devices.touch->ref++; - } - if (dev->created) { - wl_signal_emit(&tz_devicemgr->backend->events.new_input, - dev->input_device); - } - } - - if (inited) { - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - if (client_data->init == false) { - client_data->init = true; - client_data->clas = clas; - } - break; - } - } - } - - return ret; -} - -static int -tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, - struct wl_resource *resource) -{ - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - struct ds_tizen_input_devicemgr_client *client_data; - struct ds_tizen_input_devicemgr_device *dev; - uint32_t clas = 0; - int i = 0; - bool res; - - ds_inf("Deinit generator."); - wl_list_for_each(client_data, &tz_devicemgr->clients, link) { - if (client_data->resource == resource) { - if (client_data->init == true) { - client_data->init = false; - clas = client_data->clas; - break; - } else { - return ret; - } - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - dev = tz_devicemgr->devices.kbd; - dev->ref--; - if (dev->ref<= 0) { - dev->ref = 0; - tz_devicemgr_pressed_keys_cleanup(tz_devicemgr); - - if (dev->created) { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { - dev = tz_devicemgr->devices.ptr; - dev->ref--; - if (dev->ref <= 0) { - dev->ref = 0; - while(dev->mouse.pressed) - { - if (dev->mouse.pressed & (1 << i)) - { - res = tz_devicemgr_generate_mouse_button(dev->input_device, - i + 1, false); - if (!res) break; - dev->mouse.pressed &= ~(1 << i); - } - i++; - if (i >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) break; - } - - if (dev->created) - { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { - dev = tz_devicemgr->devices.touch; - dev->ref--; - if (dev->ref <= 0) { - dev->ref = 0; - while(dev->touch.pressed) - { - if (dev->touch.pressed & (1 << i)) - { - res = tz_devicemgr_generate_touch_up(dev->input_device, - i); - if (!res) break; - dev->touch.pressed &= ~(1 << i); - } - i++; - if (i >= tz_devicemgr->touch_max_count) break; - } - - if (dev->created) - { - tz_devicemgr_device_close(dev); - dev->created = false; - } - free(dev->name); - dev->name = NULL; - } - } - - return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; -} - -static int -tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name) -{ - struct ds_tizen_input_devicemgr_keymap_data *data; - - if (!wl_list_empty(list)) { - wl_list_for_each(data, list, link) { - if (!strcmp(data->name, name)) { - return data->keycode; - } - } - } - - return 0; -} - -static bool -tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, - int pressed) -{ - struct ds_event_keyboard_key ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_keyboard *kbd; - - kbd = ds_input_device_get_keyboard(device); - if (!kbd) { - ds_err("No ds_keyboard to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.keycode = keycode - 8; - if (pressed) - ds_event.state = WL_KEYBOARD_KEY_STATE_PRESSED; - else - ds_event.state = WL_KEYBOARD_KEY_STATE_RELEASED; - - ds_inf("Generate key. kbd:%p, key:%d, state:%s", kbd, ds_event.keycode, - (ds_event.state == WL_KEYBOARD_KEY_STATE_PRESSED) ? - "PRESSED" : "RELEASED"); - - ds_keyboard_notify_key(kbd, &ds_event); - - return true; -} - -static bool -tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, - int keycode, bool pressed) -{ - struct ds_tizen_input_devicemgr_key_info *key, *tmp; - - if (pressed) { - key = calloc(1, sizeof(*key)); - if (!key) { - ds_err("Failed to alloc keydata memory.\n"); - return false; - } - key->keycode = keycode; - wl_list_init(&key->link); - wl_list_insert(&tz_devicemgr->devices.kbd->key.pressed, &key->link); - } - else { - wl_list_for_each_safe(key, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { - if (key->keycode == keycode) { - wl_list_remove(&key->link); - free(key); - break; - } - } - } - - ds_inf("Update pressed keys. length: %d, keycode:%d, pressed:%d", - wl_list_length(&tz_devicemgr->devices.kbd->key.pressed), keycode, pressed); - - return true; -} - -static void -tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - - ds_inf("Clean up the kbd.pressed_keys. length: %d", - wl_list_length(&tz_devicemgr->devices.kbd->key.pressed)); - - wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { - if (tz_devicemgr->devices.kbd) - tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, - keydata->keycode, false); - wl_list_remove(&keydata->link); - free(keydata); - } -} - -static void -tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_keymap_data *keymap, *tmp; - - ds_inf("Clean up the keymap_list. length: %d", - wl_list_length(&tz_devicemgr->keymap_list)); - - wl_list_for_each_safe(keymap, tmp, &tz_devicemgr->keymap_list, link) { - free(keymap->name); - wl_list_remove(&keymap->link); - free(keymap); - } -} - -static bool -tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, - uint32_t finger) -{ - struct ds_event_touch_motion ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_event.x = x; - ds_event.y = y; - ds_inf("Generate touch motion. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); - - wl_signal_emit(&touch->events.motion, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, - uint32_t finger) -{ - struct ds_event_touch_down ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_event.x = x; - ds_event.y = y; - ds_inf("Generate touch down. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); - - wl_signal_emit(&touch->events.down, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger) -{ - struct ds_event_touch_up ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_touch *touch; - - touch = ds_input_device_get_touch(device); - if (!touch) { - ds_err("No ds_touch to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.id = finger; - ds_inf("Generate touch up. touch:%p, id:%d", touch, ds_event.id); - - wl_signal_emit(&touch->events.up, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y) -{ - struct ds_event_pointer_motion ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_pointer *pointer; - - pointer = ds_input_device_get_pointer(device); - if (!pointer) { - ds_err("No ds_pointer to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.delta_x = x; - ds_event.delta_y = y; - ds_inf("Generate mouse motion. pointer:%p, x:%f, y:%f", pointer, ds_event.delta_x, ds_event.delta_y); - - wl_signal_emit(&pointer->events.motion, &ds_event); - - return true; -} - -static bool -tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state) -{ - struct ds_event_pointer_button ds_event; - struct timeval time; - unsigned int timestamp; - struct ds_pointer *pointer; - - pointer = ds_input_device_get_pointer(device); - if (!pointer) { - ds_err("No ds_pointer to notify event"); - return false; - } - - gettimeofday(&time, NULL); - timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; - - ds_event.time_msec = timestamp; - ds_event.button = button; - if (state) - ds_event.state = DS_BUTTON_PRESSED; - else - ds_event.state = DS_BUTTON_RELEASED; - ds_inf("Generate mouse button. pointer:%p, button:%d, state:%s", pointer, ds_event.button, state ? "PRESSED" : "RELEASED"); - - wl_signal_emit(&pointer->events.button, &ds_event); - - return true; -} - -static void -devicemgr_keyboard_grab_iface_enter(struct ds_seat_keyboard_grab *grab, - struct ds_surface *surface, uint32_t keycodes[], - size_t num_keycodes, struct ds_keyboard_modifiers *modifiers) -{ - ds_inf("devicemgr. keyboard_grab_iface_enter"); -} - -static void -devicemgr_keyboard_grab_iface_clear_focus(struct ds_seat_keyboard_grab *grab) -{ - ds_inf("devicemgr. keyboard_grab_iface_clear_focus"); -} - -static void -tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - - ds_inf("Clean up the blocked keys. length: %d", - wl_list_length(&tz_devicemgr->blocked_keys)); - - wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->blocked_keys, link) { - wl_list_remove(&keydata->link); - free(keydata); - } -} - -static void -devicemgr_keyboard_grab_iface_key(struct ds_seat_keyboard_grab *grab, - uint32_t time_msec, uint32_t key, uint32_t state) -{ - struct ds_tizen_input_devicemgr *devicemgr; - struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; - bool key_blocked = false; - - ds_inf("devicemgr. keyboard_grab_iface_key"); - - devicemgr = ds_seat_keyboard_grab_get_data(grab); - if (!devicemgr->block_resource) { - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - goto finish; - } - else { - wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { - if (keydata->keycode == (int)key) { - wl_list_remove(&keydata->link); - free(keydata); - key_blocked = true; - break; - } - } - if (wl_list_empty(&devicemgr->blocked_keys)) { - tz_devicemgr_ungrab_keyboard(devicemgr); - } - if (key_blocked) { - goto finish; - } - } - } - - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - keydata = calloc(1, sizeof (*keydata)); - if (!keydata) - goto finish; - keydata->keycode = key; - wl_list_init(&keydata->link); - wl_list_insert(&devicemgr->blocked_keys, &keydata->link); - key_blocked = true; - } - else { - if (wl_list_empty(&devicemgr->blocked_keys)) - goto finish; - wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { - if (keydata->keycode == (int)key) { - wl_list_remove(&keydata->link); - free(keydata); - key_blocked = true; - } - } - } - -finish: - if (!key_blocked) - ds_inf("block key event: (%d %s)\n", key, (state ? "press" : "release")); -} - -static void -devicemgr_modifiers_grab_iface_key(struct ds_seat_keyboard_grab *grab, - struct ds_keyboard_modifiers *modifiers) -{ - ds_inf("devicemgr. modifiers_grab_iface_key"); -} - -static void -devicemgr_cancel_grab_iface_key(struct ds_seat_keyboard_grab *grab) -{ - ds_inf("devicemgr. cancel_grab_iface_key"); -} - -static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface = { - .enter = devicemgr_keyboard_grab_iface_enter, - .clear_focus = devicemgr_keyboard_grab_iface_clear_focus, - .key = devicemgr_keyboard_grab_iface_key, - .modifiers = devicemgr_modifiers_grab_iface_key, - .cancel = devicemgr_cancel_grab_iface_key, -}; - -static void -tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - ds_seat_keyboard_start_grab(tz_devicemgr->seat, tz_devicemgr->grab); -} - -static void -tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - ds_seat_keyboard_end_grab(tz_devicemgr->seat); -} - -static void -tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr) -{ - if (wl_list_empty(&tz_devicemgr->blocked_keys)) - tz_devicemgr_ungrab_keyboard(tz_devicemgr); - - tz_devicemgr->block_resource = NULL; -} - -static bool -devicemgr_add_timer(struct ds_tizen_input_devicemgr *tz_devicemgr, - wl_event_loop_timer_func_t func, int time) -{ - struct wl_event_loop *event_loop; - - event_loop = wl_display_get_event_loop(tz_devicemgr->backend->display); - if (!event_loop) { - ds_err("Failed to get event_loop from display: %p", - tz_devicemgr->backend->display); - return false; - } - - tz_devicemgr->timer = wl_event_loop_add_timer(event_loop, func, - tz_devicemgr); - if (!tz_devicemgr->timer) { - ds_err("Failed to timer"); - return false; - } - wl_event_source_timer_update(tz_devicemgr->timer, time); - - return true; -} - -static int -devicemgr_block_timer(void *data) -{ - struct ds_tizen_input_devicemgr *devicemgr = data; - - tizen_input_device_manager_send_block_expired(devicemgr->block_resource); - - tz_devicemgr_ungrab_keyboard_check(devicemgr); - - wl_event_source_remove(devicemgr->timer); - devicemgr->timer = NULL; - - return 1; -} - -static void -device_manager_handle_block_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial, uint32_t clas, - uint32_t duration) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - bool res; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_BLOCK)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { - ds_err("only support keyboard device. (requested: 0x%x)\n", clas); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - if(tz_devicemgr->block_resource) { - ds_err("currently the input system is already blocked\n"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - res = devicemgr_add_timer(tz_devicemgr, devicemgr_block_timer, duration); - if (!res) { - ds_err("Failed to add a timer\n"); - goto finish; - } - - tz_devicemgr_grab_keyboard(tz_devicemgr); - tz_devicemgr->block_resource = resource; - ds_inf("Block events. clas: %d, duration:%d", clas, duration); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - -static void -device_manager_handle_unblock_events(struct wl_client *client, - struct wl_resource *resource, uint32_t serial) -{ - struct ds_tizen_input_devicemgr *tz_devicemgr; - int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; - - tz_devicemgr = wl_resource_get_user_data(resource); - - if (!tz_devicemgr_check_privilege(tz_devicemgr, client, - TIZEN_PRIV_INPUT_BLOCK)) { - ds_err("No permission to input generate"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; - goto finish; - } - - if (tz_devicemgr->block_resource != resource) { - ds_err("currently the input system is blocked by another resource"); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; - goto finish; - } - - tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); - tz_devicemgr->block_resource = NULL; - ds_inf("Unblock events."); - ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; - - if (tz_devicemgr->timer) { - wl_event_source_remove(tz_devicemgr->timer); - tz_devicemgr->timer = NULL; - } - -finish: - tizen_input_device_manager_send_error(resource, ret); -} - diff --git a/src/input-devicemgr/input-devicemgr.h b/src/input-devicemgr/input-devicemgr.h deleted file mode 100644 index a4428ee..0000000 --- a/src/input-devicemgr/input-devicemgr.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef DS_TIZEN_DEVICEMGR_H -#define DS_TIZEN_DEVICEMGR_H - -#include -#include -#include -#include -#include -#include - -struct ds_tizen_input_devicemgr_device { - char *name; - struct ds_input_device *input_device; - int ref; - - bool created; - - struct { - struct wl_list pressed; - } key; - - struct { - unsigned int pressed; - } touch; - - struct { - unsigned int pressed; - } mouse; -}; - -struct ds_tizen_input_devicemgr { - struct wl_global *global; - struct wl_display *display; - struct ds_backend *backend; - struct ds_seat *seat; - - struct { - struct wl_signal destroy; - } events; - - struct wl_listener new_input; - struct wl_listener backend_destroy; - struct wl_listener seat_destroy; - struct { - struct ds_tizen_input_devicemgr_device *kbd; - struct ds_tizen_input_devicemgr_device *ptr; - struct ds_tizen_input_devicemgr_device *touch; - } devices; - - struct wl_list clients; - - struct wl_list keymap_list; - - struct wl_list blocked_keys; - struct wl_resource *block_resource; - struct wl_event_source *timer; - struct ds_seat_keyboard_grab *grab; - int touch_max_count; - - struct { - uint32_t width; - uint32_t height; - } output; -}; - -struct ds_tizen_input_devicemgr_client { - struct wl_resource *resource; - bool init; - uint32_t clas; - struct wl_list link; // ds_tizen_input_devicemgr::clients -}; - -struct ds_tizen_input_devicemgr_key_info { - int keycode; - struct wl_list link; // ds_tizen_input_devicemgr::pressed_keys; -}; - -#endif diff --git a/src/input-devicemgr/meson.build b/src/input-devicemgr/meson.build deleted file mode 100644 index 4616f6f..0000000 --- a/src/input-devicemgr/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -libds_tizen_input_devicemgr_files = [ - tizen_security_files, - 'input-devicemgr.c', -] - -libds_tizen_input_devicemgr_deps = [ - deps_libds_tizen, - deps_tizen_security, - dependency('tizen-extension-server', required: true), - dependency('xkbcommon', required: true), -] - -lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', libds_tizen_input_devicemgr_files, - dependencies: libds_tizen_input_devicemgr_deps, - include_directories: [ common_inc, include_directories('.'), include_directories('..') ], - version: meson.project_version(), - install: true -) - -deps_libds_tizen_input_devicemgr = declare_dependency( - link_with: lib_libds_tizen_input_devicemgr, - dependencies: libds_tizen_input_devicemgr_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen_input_devicemgr, - version: meson.project_version(), - filebase: 'libds-tizen-input-devicemgr', - name: 'libds-tizen-input-devicemgr', - description: 'tizen input devicemgr extension of libds-tizen for tizen platform', -) diff --git a/src/meson.build b/src/meson.build index b4b92f5..46d807d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,8 +28,8 @@ deps_tizen_security = [ ] subdir('allocator') -subdir('tbm-server') +subdir('tbm_server') subdir('backend') subdir('keyrouter') -subdir('input-devicemgr') +subdir('input_devicemgr') subdir('dpms') diff --git a/src/tbm-server/meson.build b/src/tbm-server/meson.build deleted file mode 100644 index ced06a4..0000000 --- a/src/tbm-server/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -libds_tizen_tbm_server_files = [ - 'pixel_format.c', - 'tbm-server.c', -] - -libds_tizen_tbm_server_deps = [ - deps_libds_tizen, - dependency('libdrm', required: true), - dependency('libtbm', required: true), - dependency('wayland-tbm-server', required: true), -] - -lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_tbm_server_files, - dependencies: libds_tizen_tbm_server_deps, - include_directories: [ common_inc, include_directories('.'), include_directories('..') ], - version: meson.project_version(), - install: true -) - -deps_libds_tizen_tbm_server = declare_dependency( - link_with: lib_libds_tizen_tbm_server, - dependencies: libds_tizen_tbm_server_deps, - include_directories: [ common_inc, include_directories('.') ], -) - -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds_tizen_tbm_server, - version: meson.project_version(), - filebase: 'libds-tizen-tbm-server', - name: 'libds-tizen-tbm-server', - description: 'wayland-tbm extension of libds-tizen for tizen platform', -) diff --git a/src/tbm-server/pixel_format.c b/src/tbm-server/pixel_format.c deleted file mode 100644 index 030f211..0000000 --- a/src/tbm-server/pixel_format.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include - -#include -#include "pixel_format.h" - -#ifdef ARRAY_LENGTH -#undef ARRAY_LENGTH -#endif - -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) - -struct ds_tbm_format -{ - uint32_t drm_format; - uint32_t tbm_format; -}; - -static const struct ds_tbm_format formats[] = -{ - { - .drm_format = DRM_FORMAT_ARGB8888, - .tbm_format = TBM_FORMAT_ARGB8888, - }, - { - .drm_format = DRM_FORMAT_XRGB8888, - .tbm_format = TBM_FORMAT_XRGB8888, - }, - /* TODO more format */ -}; - -uint32_t -convert_drm_format_to_tbm(uint32_t fmt) -{ - size_t i; - - for (i = 0; i < ARRAY_LENGTH(formats); i++) { - if (formats[i].drm_format == fmt) - return formats[i].tbm_format; - } - - ds_err("DRM format 0x%"PRIX32" has no TBM equivalent", fmt); - - return 0; -} - -uint32_t -convert_tbm_format_to_drm(uint32_t fmt) -{ - size_t i; - - for (i = 0; i < ARRAY_LENGTH(formats); i++) { - if (formats[i].tbm_format == fmt) - return formats[i].drm_format; - } - - ds_err("TBM format 0x%"PRIX32" has no DRM equivalent", fmt); - - return 0; -} diff --git a/src/tbm-server/pixel_format.h b/src/tbm-server/pixel_format.h deleted file mode 100644 index a63d096..0000000 --- a/src/tbm-server/pixel_format.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DS_TIZEN_PIXEL_FORMAT_H -#define DS_TIZEN_PIXEL_FORMAT_H - -#include - -uint32_t convert_drm_format_to_tbm(uint32_t fmt); - -uint32_t convert_tbm_format_to_drm(uint32_t fmt); - -#endif diff --git a/src/tbm-server/tbm-server.c b/src/tbm-server/tbm-server.c deleted file mode 100644 index 9dde248..0000000 --- a/src/tbm-server/tbm-server.c +++ /dev/null @@ -1,268 +0,0 @@ -#include -#include -#include - -#include - -#include -#include "pixel_format.h" -#include "tbm-server.h" - -static const struct ds_buffer_resource_interface tbm_buffer_resource_iface; -static const struct ds_buffer_interface tbm_client_buffer_iface; - -static void tbm_server_handle_display_destroy(struct wl_listener *listener, - void *data); - -WL_EXPORT struct ds_tbm_server * -ds_tbm_server_create(struct wl_display *display) -{ - struct ds_tbm_server *tbm; - tbm_bufmgr bufmgr; - - tbm = calloc(1, sizeof *tbm); - if (!tbm) - return NULL; - - wl_signal_init(&tbm->events.destroy); - - tbm->wl_tbm = wayland_tbm_server_init(display, NULL, -1, 0); - if (!tbm->wl_tbm) { - goto err_wl_tbm; - } - - bufmgr = wayland_tbm_server_get_bufmgr(tbm->wl_tbm); - if (!bufmgr) { - goto err_bind; - } - - if (!tbm_bufmgr_bind_native_display(bufmgr, (void *)display)) { - goto err_bind; - } - - tbm->display_destroy.notify = tbm_server_handle_display_destroy; - wl_display_add_destroy_listener(display, &tbm->display_destroy); - - ds_buffer_register_resource_interface(&tbm_buffer_resource_iface); - - return tbm; - -err_bind: - wayland_tbm_server_deinit(tbm->wl_tbm); -err_wl_tbm: - free(tbm); - - return NULL; -} - -WL_EXPORT void -ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, - struct wl_listener *listener) -{ - wl_signal_add(&tbm->events.destroy, listener); -} - -WL_EXPORT struct ds_tbm_client_buffer * -ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) -{ - if (ds_buffer->iface != &tbm_client_buffer_iface) - return NULL; - return (struct ds_tbm_client_buffer *)ds_buffer; -} - -WL_EXPORT tbm_surface_h -ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer) -{ - if (buffer->base.iface != &tbm_client_buffer_iface) - return NULL; - return buffer->surface; -} - -static void -tbm_server_handle_display_destroy(struct wl_listener *listener, void *data) -{ - struct ds_tbm_server *tbm; - - tbm = wl_container_of(listener, tbm, display_destroy); - - wl_signal_emit(&tbm->events.destroy, tbm); - - wayland_tbm_server_deinit(tbm->wl_tbm); - free(tbm); -} - -static void -tbm_client_buffer_handle_release(struct wl_listener *listener, void *data) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = wl_container_of(listener, buffer, buffer_release); - if (buffer->resource) - wl_buffer_send_release(buffer->resource); -} - -static void -tbm_client_buffer_handle_resource_destroy(struct wl_listener *listener, - void *data) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = wl_container_of(listener, buffer, resource_destroy); - - buffer->resource = NULL; - buffer->surface = NULL; - wl_list_remove(&buffer->resource_destroy.link); - wl_list_init(&buffer->resource_destroy.link); - - ds_buffer_drop(&buffer->base); -} - -static struct ds_tbm_client_buffer * -tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) -{ - assert(ds_buffer->iface == &tbm_client_buffer_iface); - return (struct ds_tbm_client_buffer *)ds_buffer; -} - -static void -tbm_client_buffer_iface_destroy(struct ds_buffer *ds_buffer) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - ds_inf("Destroy TBM client buffer(%p)", buffer); - - wl_list_remove(&buffer->resource_destroy.link); - wl_list_remove(&buffer->buffer_release.link); - free(buffer); -} - -static bool -tbm_client_buffer_iface_begin_data_ptr_access(struct ds_buffer *ds_buffer, - enum ds_buffer_data_ptr_access_flag flags, void **data, - uint32_t *format, size_t *stride) -{ - struct ds_tbm_client_buffer *buffer; - tbm_surface_info_s info; - tbm_bo_access_option op = TBM_OPTION_NONE; - int err; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - if (flags & DS_BUFFER_DATA_PTR_ACCESS_READ) - op |= TBM_OPTION_READ; - - if (flags & DS_BUFFER_DATA_PTR_ACCESS_WRITE) - op |= TBM_OPTION_WRITE; - - err = tbm_surface_map(buffer->surface, op, &info); - if (err != TBM_SURFACE_ERROR_NONE) { - ds_err("Failed tbm_surface_map()"); - return false; - } - - *format = convert_tbm_format_to_drm(buffer->format); - *stride = info.planes[0].stride; - *data = info.planes[0].ptr; - - return true; -} - -static void -tbm_client_buffer_iface_end_ptr_access(struct ds_buffer *ds_buffer) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_from_buffer(ds_buffer); - - tbm_surface_unmap(buffer->surface); -} - -static const struct ds_buffer_interface tbm_client_buffer_iface = { - .destroy = tbm_client_buffer_iface_destroy, - .begin_data_ptr_access = tbm_client_buffer_iface_begin_data_ptr_access, - .end_data_ptr_access = tbm_client_buffer_iface_end_ptr_access, -}; - -static struct ds_tbm_client_buffer * -tbm_client_buffer_create(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - tbm_surface_h surface; - int32_t width, height; - - surface = wayland_tbm_server_get_surface(NULL, resource); - if (!surface) { - ds_err("Could not get tbm_surface from wl_resource@%d", - wl_resource_get_id(resource)); - return NULL; - } - - width = tbm_surface_get_width(surface); - height = tbm_surface_get_height(surface); - - buffer = calloc(1, sizeof *buffer); - if (!buffer) - return NULL; - - ds_buffer_init(&buffer->base, &tbm_client_buffer_iface, width, height); - - buffer->resource = resource; - buffer->surface = surface; - buffer->format = tbm_surface_get_format(surface); - - buffer->buffer_release.notify = tbm_client_buffer_handle_release; - ds_buffer_add_release_listener(&buffer->base, &buffer->buffer_release); - - buffer->resource_destroy.notify = - tbm_client_buffer_handle_resource_destroy; - wl_resource_add_destroy_listener(resource, &buffer->resource_destroy); - - ds_inf("TBM client buffer(%p) created", buffer); - - return buffer; -} - -static struct ds_tbm_client_buffer * -tbm_client_buffer_get_or_create(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - struct wl_listener *resource_destroy_listener; - - resource_destroy_listener = wl_resource_get_destroy_listener(resource, - tbm_client_buffer_handle_resource_destroy);; - if (resource_destroy_listener) { - buffer = wl_container_of(resource_destroy_listener, - buffer, resource_destroy); - return buffer; - } - - return tbm_client_buffer_create(resource); -} - -static bool -tbm_buffer_resource_iface_is_instance(struct wl_resource *resource) -{ - return !!wayland_tbm_server_get_surface(NULL, resource); -} - -static struct ds_buffer * -tbm_buffer_resource_iface_from_resource(struct wl_resource *resource) -{ - struct ds_tbm_client_buffer *buffer; - - buffer = tbm_client_buffer_get_or_create(resource); - if (!buffer) { - ds_err("Could not get or create ds_tbm_client_buffer"); - return NULL; - } - - return &buffer->base; -} - -static const struct ds_buffer_resource_interface tbm_buffer_resource_iface = { - .name = "tbm", - .is_instance = tbm_buffer_resource_iface_is_instance, - .from_resource = tbm_buffer_resource_iface_from_resource, -}; diff --git a/src/tbm-server/tbm-server.h b/src/tbm-server/tbm-server.h deleted file mode 100644 index 58e391b..0000000 --- a/src/tbm-server/tbm-server.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DS_TIZEN_TBM_SERVER_H -#define DS_TIZEN_TBM_SERVER_H - -#include -#include -#include -#include - -struct ds_tbm_server -{ - struct wayland_tbm_server *wl_tbm; - - struct wl_listener display_destroy; - - struct { - struct wl_signal destroy; - } events; -}; - -struct ds_tbm_client_buffer -{ - struct ds_buffer base; - - tbm_surface_h surface; - struct wl_resource *resource; - - struct wl_listener buffer_release; - struct wl_listener resource_destroy; - - uint32_t format; - size_t stride; -}; - -#endif diff --git a/tests/meson.build b/tests/meson.build index dae7875..324c760 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,12 +1,12 @@ tests = [ - { 'name': 'test-compositor' }, - { 'name': 'test-backend' }, + { 'name': 'test_compositor' }, + { 'name': 'test_backend' }, { - 'name': 'test-surface', + 'name': 'test_surface', 'deps': [ dependency('wayland-client') ], }, { - 'name': 'test-subsurface', + 'name': 'test_subsurface', 'deps': [ dependency('wayland-client') ], }, ] diff --git a/tests/test-backend.c b/tests/test-backend.c deleted file mode 100644 index 69417b6..0000000 --- a/tests/test-backend.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -#include -#include - -static struct ds_backend * -create_possible_wl_backend(struct wl_display *display) -{ - struct ds_backend *backend; - char wl_name[512]; - - for (int i = 0; i < 5; i++) { - snprintf(wl_name, sizeof wl_name, "wayland-%d", i); - backend = ds_wl_backend_create(display, wl_name); - if (backend) - break; - } - - return backend; -} - -static void -test_wl_backend_create(void) -{ - struct wl_display *display; - struct ds_backend *backend; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - ds_backend_destroy(backend); -} - -struct test -{ - struct wl_listener backend_destroy; - bool cb_called; -}; - -static void -cb_backend_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, backend_destroy); - test->cb_called = true; -} - -static void -test_wl_backend_destroy_signal(void) -{ - struct wl_display *display; - struct ds_backend *backend; - struct test test; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - test.cb_called = false; - test.backend_destroy.notify = cb_backend_destroy; - ds_backend_add_destroy_listener(backend, &test.backend_destroy); - - wl_display_destroy(display); - assert(test.cb_called); -} - -int -main(void) -{ - test_wl_backend_create(); - test_wl_backend_destroy_signal(); - - return 0; -} diff --git a/tests/test-compositor.c b/tests/test-compositor.c deleted file mode 100644 index b5883a5..0000000 --- a/tests/test-compositor.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include -#include -#include - -static void -test_compositor_create(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - wl_display_destroy(display); -} - -struct test -{ - struct wl_listener compositor_destroy; - bool destroyed; -}; - -static void -cb_compositor_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, compositor_destroy); - test->destroyed = true; -} - -static void -test_compositor_destroy_signal(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - struct test test; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - test.destroyed = false; - test.compositor_destroy.notify = cb_compositor_destroy; - ds_compositor_add_destroy_listener(compositor, - &test.compositor_destroy); - - wl_display_destroy(display); - assert(test.destroyed == true); -} - -int -main(void) -{ - test_compositor_create(); - test_compositor_destroy_signal(); - - return 0; -} diff --git a/tests/test-subsurface.c b/tests/test-subsurface.c deleted file mode 100644 index 98e830d..0000000 --- a/tests/test-subsurface.c +++ /dev/null @@ -1,211 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -const char * -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); - - return server->socket; -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_subcompositor *subcompositor; - struct wl_surface *surface; - struct wl_subsurface *subsurface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } - else if (strcmp(interface, "wl_subcompositor") == 0) { - client->subcompositor = - wl_registry_bind(registry, id, &wl_subcompositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); - assert(client->subcompositor); -} - -void -test_client_finish(struct client *client) -{ - wl_subcompositor_destroy(client->subcompositor); - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server -{ - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener new_subsurface1; - struct wl_listener new_subsurface2; -}; - -static void -cb_new_subsurface1(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface1); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_subsurface2(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface2); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - if (!server->new_subsurface1.notify) { - server->new_subsurface1.notify = cb_new_subsurface1; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface1); - } - else { - server->new_subsurface2.notify = cb_new_subsurface2; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface2); - } -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - struct wl_surface *child_surface = - wl_compositor_create_surface(client.compositor); - - struct wl_subsurface *subsurface = - wl_subcompositor_get_subsurface(client.subcompositor, - child_surface, surface); - - wl_display_roundtrip(client.display); - - wl_subsurface_destroy(subsurface); - wl_surface_destroy(child_surface); - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_subsurface_create(void) -{ - struct test_server server = { - .new_subsurface1 = { .notify = NULL }, - .cb_called = false - }; - pid_t pid; - - const char *socket_name = test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(socket_name); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_subsurface_create(); - return 0; -} diff --git a/tests/test-surface.c b/tests/test-surface.c deleted file mode 100644 index eab2b77..0000000 --- a/tests/test-surface.c +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -void -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_surface *surface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); -} - -void -test_client_finish(struct client *client) -{ - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server { - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener surface_destroy; -}; - -static void -cb_surface_destroy(struct wl_listener *listener, void *data) -{ - struct test_server *server; - - server = wl_container_of(listener, server, surface_destroy); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - server->surface_destroy.notify = cb_surface_destroy; - ds_surface_add_destroy_listener(surface, &server->surface_destroy); -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - wl_display_roundtrip(client.display); - - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_surface_create_and_destroy(void) -{ - struct test_server server = { .cb_called = false }; - pid_t pid; - - test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(server.base.socket); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_surface_create_and_destroy(); - return 0; -} -- 2.7.4 From beaddc72e08eea8791b6d5aed9acec35d01852b9 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 4 Jul 2022 19:33:18 +0900 Subject: [PATCH 13/16] fix the typo Change-Id: Ie2407006a7d008b8a1c5d32413cf9a64669693e5 --- src/dpms/dpms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpms/dpms.c b/src/dpms/dpms.c index a85834a..833005f 100644 --- a/src/dpms/dpms.c +++ b/src/dpms/dpms.c @@ -29,7 +29,7 @@ struct ds_tizen_dpms static void dpms_handle_display_destroy(struct wl_listener *listener, void *data); static void dpms_bind(struct wl_client *wl_client, void *data, - uint32_t verison, uint32_t id); + uint32_t version, uint32_t id); WL_EXPORT struct ds_tizen_dpms * ds_tizen_dpms_create(struct wl_display *display) -- 2.7.4 From 0f72718246529b64ae641457786f47d3d5c734e3 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 6 Jul 2022 14:10:33 +0900 Subject: [PATCH 14/16] add missing files Change-Id: Ifd75994c3ae705441947e2b225adfb08bacc0466 --- include/libds-tizen/input_devicemgr.h | 44 + include/libds-tizen/tbm_server.h | 33 + src/input_devicemgr/input_devicemgr.c | 1551 +++++++++++++++++++++++++++++++++ src/input_devicemgr/input_devicemgr.h | 78 ++ src/input_devicemgr/meson.build | 32 + src/tbm_server/meson.build | 32 + src/tbm_server/pixel_format.c | 61 ++ src/tbm_server/pixel_format.h | 10 + src/tbm_server/tbm_server.c | 268 ++++++ src/tbm_server/tbm_server.h | 34 + tests/test_backend.c | 80 ++ tests/test_compositor.c | 63 ++ tests/test_subsurface.c | 211 +++++ tests/test_surface.c | 162 ++++ 14 files changed, 2659 insertions(+) create mode 100644 include/libds-tizen/input_devicemgr.h create mode 100644 include/libds-tizen/tbm_server.h create mode 100644 src/input_devicemgr/input_devicemgr.c create mode 100644 src/input_devicemgr/input_devicemgr.h create mode 100644 src/input_devicemgr/meson.build create mode 100644 src/tbm_server/meson.build create mode 100644 src/tbm_server/pixel_format.c create mode 100644 src/tbm_server/pixel_format.h create mode 100644 src/tbm_server/tbm_server.c create mode 100644 src/tbm_server/tbm_server.h create mode 100644 tests/test_backend.c create mode 100644 tests/test_compositor.c create mode 100644 tests/test_subsurface.c create mode 100644 tests/test_surface.c diff --git a/include/libds-tizen/input_devicemgr.h b/include/libds-tizen/input_devicemgr.h new file mode 100644 index 0000000..fc1060e --- /dev/null +++ b/include/libds-tizen/input_devicemgr.h @@ -0,0 +1,44 @@ +#ifndef LIBDS_TIZEN_INPUT_DEVICEMGR_H +#define LIBDS_TIZEN_INPUT_DEVICEMGR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ds_tizen_input_devicemgr; +struct ds_backend; +struct ds_seat; + +struct ds_tizen_input_devicemgr_keymap_data +{ + char *name; + int keycode; + + struct wl_list link; +}; + +struct ds_tizen_input_devicemgr * +ds_tizen_input_devicemgr_create(struct ds_backend *backend, + struct ds_seat *seat); + +void +ds_tizen_input_devicemgr_add_destroy_listener( + struct ds_tizen_input_devicemgr *devicemgr, + struct wl_listener *listener); + +bool +ds_tizen_input_devicemgr_set_keymap_list( + struct ds_tizen_input_devicemgr *devicemgr, + struct wl_list *list); + +bool +ds_tizen_input_devicemgr_set_output_width_height( + struct ds_tizen_input_devicemgr *devicemgr, + uint32_t width, uint32_t height); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libds-tizen/tbm_server.h b/include/libds-tizen/tbm_server.h new file mode 100644 index 0000000..6e3b148 --- /dev/null +++ b/include/libds-tizen/tbm_server.h @@ -0,0 +1,33 @@ +#ifndef LIBDS_TIZEN_TBM_SERVER_H +#define LIBDS_TIZEN_TBM_SERVER_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ds_tbm_server; + +struct ds_tbm_client_buffer; + +struct ds_tbm_server * +ds_tbm_server_create(struct wl_display *display); + +void +ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, + struct wl_listener *listener); + +struct ds_tbm_client_buffer * +ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer); + +tbm_surface_h +ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/input_devicemgr/input_devicemgr.c b/src/input_devicemgr/input_devicemgr.c new file mode 100644 index 0000000..f690fe7 --- /dev/null +++ b/src/input_devicemgr/input_devicemgr.c @@ -0,0 +1,1551 @@ +#include +#include // gettimeofday() +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "security.h" +#include "input_devicemgr.h" + +#define TIZEN_INPUT_DEVICEMGR_VERSION 4 +#define TIZEN_PRIV_INPUT_GENERATOR "http://tizen.org/privilege/inputgenerator" +#define TIZEN_PRIV_INPUT_BLOCK "http://tizen.org/privilege/internal/inputdevice.block" +#define TIZEN_INPUT_DEVICEMGR_MAX_BTN 16 + +static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface; + +//listeners +static void +backend_handle_destroy(struct wl_listener *listener, void *data); +static void +backend_handle_input_device_add(struct wl_listener *listener, void *data); +static void +seat_handle_destroy(struct wl_listener *listener, void *data); + +//tizen_input_device_manager bind/unbind +static void +device_manager_handle_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id); +static void +device_manager_client_handle_resource_destroy(struct wl_resource *resource); + +//tizen_input_device_manager's handlers for requests +static void +device_manager_handle_block_events(struct wl_client *client, + struct wl_resource *resource, uint32_t serial, + uint32_t clas, uint32_t duration); +static void +device_manager_handle_unblock_events(struct wl_client *client, + struct wl_resource *resource, uint32_t serial); +static void +device_manager_handle_init_generator(struct wl_client *client, + struct wl_resource *resource, uint32_t clas); +static void +device_manager_handle_init_generator_with_name(struct wl_client *client, + struct wl_resource *resource, uint32_t clas, const char *name); +static void +device_manager_handle_deinit_generator(struct wl_client *client, + struct wl_resource *resource, uint32_t clas); +static void +device_manager_handle_generate_key(struct wl_client *client, + struct wl_resource *resource, + const char *keyname, uint32_t pressed); +static void +device_manager_handle_generate_touch(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t finger); +static void +device_manager_handle_generate_pointer(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t button); +static void +device_manager_handle_destroy(struct wl_client *client, + struct wl_resource *resource); + +// +static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr); +static int +tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource, uint32_t clas, const char *name); +static int +tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource); +static bool +tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, + int pressed); +static bool +tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, + int keycode, bool pressed); +static void +tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); +static void +tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); +static int +tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name); + +static bool +tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, + uint32_t finger); +static bool +tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, + uint32_t finger); +static bool +tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger); +static bool +tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y); +static bool +tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state); + +static bool +tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_client *client, const char *rule); + +static void +tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); +static void +tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr); +static void +tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr); +static void +tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr); + +WL_EXPORT struct ds_tizen_input_devicemgr * +ds_tizen_input_devicemgr_create(struct ds_backend *backend, + struct ds_seat *seat) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + + tz_devicemgr = calloc(1, sizeof *tz_devicemgr); + if (!tz_devicemgr) { + ds_err("Fail to allocate ds_tizen_input_devicemgr"); + return NULL; + } + + tz_devicemgr->backend = backend; + tz_devicemgr->backend_destroy.notify = backend_handle_destroy; + ds_backend_add_destroy_listener(backend, &tz_devicemgr->backend_destroy); + + tz_devicemgr->seat = seat; + tz_devicemgr->seat_destroy.notify = seat_handle_destroy; + ds_seat_add_destroy_listener(seat, &tz_devicemgr->seat_destroy); + + tz_devicemgr->new_input.notify = backend_handle_input_device_add; + ds_backend_add_new_input_listener(backend, &tz_devicemgr->new_input); + + tz_devicemgr->global = wl_global_create(backend->display, + &tizen_input_device_manager_interface, + TIZEN_INPUT_DEVICEMGR_VERSION, + tz_devicemgr, device_manager_handle_bind); + if (!tz_devicemgr->global) { + goto err_global; + } + + tz_devicemgr->devices.kbd = calloc(1, + sizeof(struct ds_tizen_input_devicemgr_device)); + if (!tz_devicemgr->devices.kbd) { + goto err_kbd; + } + tz_devicemgr->devices.ptr = calloc(1, + sizeof(struct ds_tizen_input_devicemgr_device)); + if (!tz_devicemgr->devices.ptr) { + goto err_ptr; + } + tz_devicemgr->devices.touch = calloc(1, + sizeof(struct ds_tizen_input_devicemgr_device)); + if (!tz_devicemgr->devices.touch) { + goto err_touch; + } + tz_devicemgr->touch_max_count = 5;//TODO: make this variable configurable + + tz_devicemgr->grab = ds_seat_create_keyboard_grab( + tz_devicemgr->seat, &devicemgr_keyboard_grab_iface, tz_devicemgr); + if (!tz_devicemgr->grab) { + goto err_grab; + } + + wl_signal_init(&tz_devicemgr->events.destroy); + wl_list_init(&tz_devicemgr->clients); + wl_list_init(&tz_devicemgr->devices.kbd->key.pressed); + wl_list_init(&tz_devicemgr->keymap_list); + wl_list_init(&tz_devicemgr->blocked_keys); + + if (!tizen_security_init()) { + ds_inf("tizen_security_init() is failed. go on without security"); + } + + ds_inf("Global created: ds_tizen_input_devicemgr(%p) ", tz_devicemgr); + return tz_devicemgr; + +err_grab: + free(tz_devicemgr->devices.touch); +err_touch: + free(tz_devicemgr->devices.ptr); +err_ptr: + free(tz_devicemgr->devices.kbd); +err_kbd: + wl_global_destroy(tz_devicemgr->global); +err_global: + wl_list_remove(&tz_devicemgr->backend_destroy.link); + wl_list_remove(&tz_devicemgr->seat_destroy.link); + wl_list_remove(&tz_devicemgr->new_input.link); + free(tz_devicemgr); + return NULL; +} + +WL_EXPORT void +ds_tizen_input_devicemgr_add_destroy_listener( + struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_listener *listener) +{ + wl_signal_add(&tz_devicemgr->events.destroy, listener); +} + +WL_EXPORT bool +ds_tizen_input_devicemgr_set_keymap_list( + struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_list *list) +{ + struct ds_tizen_input_devicemgr_keymap_data *data, *new_data; + + if (!tz_devicemgr || !list) { + ds_err("Please insert correct data\n"); + return false; + } + + wl_list_for_each(data, list, link) { + new_data = calloc(1, sizeof *data); + if (!new_data) { + ds_err("Failed to alloc memory"); + return false; + } + new_data->name = strdup(data->name); + new_data->keycode = data->keycode; + wl_list_insert(&tz_devicemgr->keymap_list, &new_data->link); + } + ds_inf("keymap set. length:%d", + wl_list_length(&tz_devicemgr->keymap_list)); + + return true; +} + +WL_EXPORT bool +ds_tizen_input_devicemgr_set_output_width_height( + struct ds_tizen_input_devicemgr *tz_devicemgr, + uint32_t width, uint32_t height) +{ + if (!tz_devicemgr) return false; + + tz_devicemgr->output.width = width; + tz_devicemgr->output.height = height; + + ds_inf("output's width: %d, height:%d", width, height); + + return true; +} + +static void +tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + struct ds_tizen_input_devicemgr_client *client_data, *tmp; + + tizen_security_finish(); + + tz_devicemgr_keymap_list_cleanup(tz_devicemgr); + tz_devicemgr_blocked_keys_cleanup(tz_devicemgr); + tz_devicemgr_ungrab_keyboard(tz_devicemgr); + ds_seat_keyboard_destroy_grab(tz_devicemgr->grab); + + wl_signal_emit(&tz_devicemgr->events.destroy, tz_devicemgr); + wl_list_remove(&tz_devicemgr->backend_destroy.link); + wl_list_remove(&tz_devicemgr->seat_destroy.link); + wl_list_remove(&tz_devicemgr->new_input.link); + + wl_global_destroy(tz_devicemgr->global); + + wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { + wl_list_remove(&client_data->link); + tz_devicemgr_deinit_generator(tz_devicemgr, client_data->resource); + + wl_resource_set_user_data(client_data->resource, NULL); + free(client_data); + } + + free(tz_devicemgr->devices.touch); + free(tz_devicemgr->devices.ptr); + free(tz_devicemgr->devices.kbd); + free(tz_devicemgr); +} + +static void +backend_handle_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + + tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy); + + ds_inf("Global destroy: ds_tizen_input_devicemgr(%p)", tz_devicemgr); + + tz_devicemgr_destroy(tz_devicemgr); +} + +static void +seat_handle_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + + tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy); + + wl_list_remove(&tz_devicemgr->seat_destroy.link); + wl_list_init(&tz_devicemgr->seat_destroy.link); + tz_devicemgr->seat = NULL; +} + +static void +tz_devicemgr_device_close(struct ds_tizen_input_devicemgr_device *dev) +{ + if (!dev->input_device) return; + ds_input_device_destroy(dev->input_device); + dev->input_device = NULL; +} + +static void +backend_handle_input_device_add(struct wl_listener *listener, void *data) +{ + struct ds_input_device *dev = data; + struct ds_tizen_input_devicemgr *tz_devicemgr; + enum ds_input_device_type dev_type; + + tz_devicemgr = wl_container_of(listener, tz_devicemgr, new_input); + + dev_type = ds_input_device_get_type(dev); + if (dev_type == DS_INPUT_DEVICE_KEYBOARD) { + if (tz_devicemgr->devices.kbd->input_device) return; + ds_inf("devicemgr's kbd device is set to dev(%p)", dev); + tz_devicemgr->devices.kbd->input_device = dev; + } + else if (dev_type == DS_INPUT_DEVICE_POINTER) { + if (tz_devicemgr->devices.ptr->input_device) return; + ds_inf("devicemgr's ptr device is set to dev(%p)", dev); + tz_devicemgr->devices.ptr->input_device = dev; + } + else if (dev_type == DS_INPUT_DEVICE_TOUCH) { + if (tz_devicemgr->devices.touch->input_device) return; + ds_inf("devicemgr's touch device is set to dev(%p)", dev); + tz_devicemgr->devices.touch->input_device = dev; + } +} + +static const struct tizen_input_device_manager_interface _devicemgr_impl = { + .block_events = device_manager_handle_block_events, + .unblock_events = device_manager_handle_unblock_events, + .init_generator = device_manager_handle_init_generator, + .deinit_generator = device_manager_handle_deinit_generator, + .generate_key = device_manager_handle_generate_key, + .generate_pointer = device_manager_handle_generate_pointer, + .generate_touch = device_manager_handle_generate_touch, + .pointer_warp = NULL, + .init_generator_with_name = + device_manager_handle_init_generator_with_name, // v2 + .destroy = device_manager_handle_destroy, // v3 + .generate_axis = NULL, // v3 + .set_touch_count = NULL, // v4 +}; + +static void +device_manager_client_handle_resource_destroy(struct wl_resource *resource) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + struct ds_tizen_input_devicemgr_client *client_data, *tmp; + + tz_devicemgr = wl_resource_get_user_data(resource); + + tz_devicemgr_deinit_generator(tz_devicemgr, resource); + + if (resource == tz_devicemgr->block_resource) { + tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); + if (tz_devicemgr->timer) { + wl_event_source_remove(tz_devicemgr->timer); + tz_devicemgr->timer = NULL; + } + } + + wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) { + wl_list_remove(&client_data->link); + free(client_data); + } + } +} + +static void +device_manager_handle_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr = data; + struct ds_tizen_input_devicemgr_client *client_data; + + client_data = calloc(1, sizeof *client_data); + if (!client_data) { + ds_err("Failed to allocate memory !\n"); + wl_client_post_no_memory(client); + return; + } + + client_data->resource = wl_resource_create(client, + &tizen_input_device_manager_interface, MIN(version,4), id); + if (!client_data->resource) { + ds_err("Failed to create resource! (ver. :%d, id:%d)", version, id); + free(client_data); + wl_client_post_no_memory(client); + return; + } + + client_data->init = false; + wl_list_init(&client_data->link); + wl_list_insert(&tz_devicemgr->clients, &client_data->link); + + wl_resource_set_implementation(client_data->resource, &_devicemgr_impl, + tz_devicemgr, device_manager_client_handle_resource_destroy); +} + +static void +device_manager_handle_init_generator(struct wl_client *client, + struct wl_resource *resource, uint32_t clas) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + + tz_devicemgr = wl_resource_get_user_data(resource); + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, + "Input Generator"); + if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + ds_err("Failed to init input generator\n"); + goto finish; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_init_generator_with_name(struct wl_client *client, + struct wl_resource *resource, uint32_t clas, const char *name) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + + tz_devicemgr = wl_resource_get_user_data(resource); + + if (!name) { + ds_err("no name for device"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas, + name); + if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + ds_err("Failed to init input generator\n"); + goto finish; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_deinit_generator(struct wl_client *client, + struct wl_resource *resource, uint32_t clas __attribute__((unused))) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + + tz_devicemgr = wl_resource_get_user_data(resource); + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + ret = tz_devicemgr_deinit_generator(tz_devicemgr, resource); + if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + ds_err("Failed to deinit input generator\n"); + goto finish; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +struct keycode_map{ + xkb_keysym_t keysym; + xkb_keycode_t keycode; +}; + +static void +find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) +{ + struct keycode_map *found_keycodes = (struct keycode_map *)data; + xkb_keysym_t keysym = found_keycodes->keysym; + int nsyms = 0; + const xkb_keysym_t *syms_out = NULL; + + if (found_keycodes->keycode) return; + + nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out); + if (nsyms && syms_out) { + if (*syms_out == keysym) { + found_keycodes->keycode = key; + } + } +} + +static void +tz_devicemgr_xkb_keycode_from_keysym(struct xkb_keymap *keymap, + xkb_keysym_t keysym, xkb_keycode_t *keycode) +{ + struct keycode_map found_keycodes = {0,}; + found_keycodes.keysym = keysym; + xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes); + + *keycode = found_keycodes.keycode; +} + +static int +tz_devicemgr_xkb_keyname_to_keycode(struct xkb_keymap *keymap, + const char *name) +{ + xkb_keysym_t keysym = 0x0; + xkb_keycode_t keycode = 0; + + if (!strncmp(name, "Keycode-", sizeof("Keycode-")-1)) { + keycode = atoi(name + 8); + } else { + keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS); + tz_devicemgr_xkb_keycode_from_keysym(keymap, keysym, &keycode); + } + + return keycode; +} + +static uint32_t +tz_devicemgr_client_get_device_clas(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource) +{ + struct ds_tizen_input_devicemgr_client *client_data; + + wl_list_for_each(client_data, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) + return client_data->clas; + } + return 0; +} + +static void +device_manager_handle_generate_key(struct wl_client *client, + struct wl_resource *resource, const char *keyname, uint32_t pressed) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + int keycode = 0; + bool res; + struct ds_keyboard *kbd; + uint32_t clas; + + tz_devicemgr = wl_resource_get_user_data(resource); + + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) == 0) + { + ds_err("Keyboard generator is not initialized by client"); + goto finish; + } + + if (!tz_devicemgr->devices.kbd || + !tz_devicemgr->devices.kbd->input_device) { + ds_err("Keyboard device is not initialized\n"); + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + // keyname to keycode using xkb_info + kbd = ds_input_device_get_keyboard( + tz_devicemgr->devices.kbd->input_device); + if (kbd->keymap) { + keycode = tz_devicemgr_xkb_keyname_to_keycode(kbd->keymap, keyname); + } + + if (keycode <= 0) { + keycode = tz_devicemgr_keyname_to_keycode(&tz_devicemgr->keymap_list, + keyname); + } + if (keycode <= 0) + goto finish; + + res = tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, + keycode, pressed); + if (!res) { + ds_err("Generating key is failed. key: %s, pressed: %d", + keyname, pressed); + goto finish; + } + res = tz_devicemgr_pressed_keys_update(tz_devicemgr, keycode, pressed); + if (!res) { + ds_err("Updating pressed keys is failed. key: %s, pressed: %d", + keyname, pressed); + goto finish; + } + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_generate_pointer(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t button) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + bool res; + bool state; + uint32_t clas; + + tz_devicemgr = wl_resource_get_user_data(resource); + + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) == 0) + { + ds_err("Pointer generator is not initialized by client"); + goto finish; + } + + if (!tz_devicemgr->devices.ptr || + !tz_devicemgr->devices.ptr->input_device) { + ds_err("Pointer device is not initialized\n"); + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (button <= 0 || button >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) + { + ds_err("Invalid button: %d\n", button); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE) { + res = tz_devicemgr_generate_mouse_move( + tz_devicemgr->devices.ptr->input_device, (double)x, (double)y); + if (!res) goto finish; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + else { + state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ? + true : false; + res = tz_devicemgr_generate_mouse_button( + tz_devicemgr->devices.ptr->input_device, button, state); + if (!res) goto finish; + if (state) tz_devicemgr->devices.ptr->mouse.pressed |= 1 << (button - 1); + else tz_devicemgr->devices.ptr->mouse.pressed &= ~(1 << (button - 1)); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_generate_touch(struct wl_client *client, + struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, + uint32_t finger) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + double transformed_x = .0, transformed_y = .0; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + bool res; + uint32_t clas; + + tz_devicemgr = wl_resource_get_user_data(resource); + + clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource); + if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) == 0) + { + ds_err("Touch generator is not initialized by client"); + goto finish; + } + + if (!tz_devicemgr->devices.touch || + !tz_devicemgr->devices.touch->input_device) { + ds_err("Touch device is not initialized\n"); + goto finish; + } + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_GENERATOR)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (finger >= tz_devicemgr->touch_max_count) + { + ds_err("Invalid fingers: %d\n", finger); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) { + transformed_x = x / (double)tz_devicemgr->output.width; + transformed_y = y / (double)tz_devicemgr->output.height; + } + + switch(type) { + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: // 0 + res = tz_devicemgr_generate_touch_move( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + res= tz_devicemgr_generate_touch_down( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + tz_devicemgr->devices.touch->touch.pressed |= 1 << finger; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END: // 2 + res = tz_devicemgr_generate_touch_up( + tz_devicemgr->devices.touch->input_device, finger); + if (!res) break; + tz_devicemgr->devices.touch->touch.pressed &= ~(1 << finger); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE: // 1 + res = tz_devicemgr_generate_touch_move( + tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger); + if (!res) break; + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + break; + default: + break; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_destroy(struct wl_client *client, + struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static bool +tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_client *client, const char *rule) +{ + pid_t pid = 0; + uid_t uid = 0; + gid_t gid = 0; + + if (!client) return false; + + wl_client_get_credentials(client, &pid, &uid, &gid); + + return tizen_security_check_privilege(pid, uid, rule); +} + +static const struct ds_input_device_interface input_device_iface = +{ + .destroy = NULL, +}; + +static struct ds_keyboard * +create_ds_keyboard() +{ + struct ds_keyboard *kbd; + kbd = calloc(1, sizeof *kbd); + if (!kbd) { + ds_err("Could not allocate memory"); + return NULL; + } + ds_keyboard_init(kbd, NULL); + + return kbd; +} + +static struct ds_pointer * +create_ds_pointer() +{ + struct ds_pointer *pointer; + pointer = calloc(1, sizeof *pointer); + if (!pointer) { + ds_err("Could not allocate memory"); + return NULL; + } + ds_pointer_init(pointer, NULL); + + return pointer; +} + +static struct ds_touch * +create_ds_touch() +{ + struct ds_touch *touch; + touch = calloc(1, sizeof *touch); + if (!touch) { + ds_err("Could not allocate memory"); + return NULL; + } + ds_touch_init(touch, NULL); + + return touch; +} + +static int +tz_devicemgr_create_device(struct ds_tizen_input_devicemgr_device *dev, + uint32_t clas, const char *name) +{ + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + const char *dev_name; + + if (dev->name && strlen(dev->name) > 0) { + ds_inf("device already has name. name:%s", dev->name); + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + + if (dev->input_device) { + dev_name = ds_input_device_get_name(dev->input_device); + ds_inf("device was already set. name:%s", dev_name); + dev->name = strdup(dev_name); + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + } + + //input_device create + dev->input_device = calloc(1, sizeof(struct ds_input_device)); + if(!dev->input_device) { + ds_err("Failed to create input device !\n"); + return ret; + } + + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_KEYBOARD, + &input_device_iface, name, -1, -1); + dev->input_device->keyboard = create_ds_keyboard(); + } + else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_POINTER, + &input_device_iface, name, -1, -1); + dev->input_device->pointer = create_ds_pointer(); + } + else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) + { + ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_TOUCH, + &input_device_iface, name, -1, -1); + dev->input_device->touch = create_ds_touch(); + } + + dev->created = true; + dev->name = strdup(name); + + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; +} + +static int +tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource, uint32_t clas, const char *name) +{ + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + struct ds_tizen_input_devicemgr_client *client_data; + struct ds_tizen_input_devicemgr_device *dev; + bool inited = false; + + ds_inf("Init generator. name:%s", name); + + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { + dev = tz_devicemgr->devices.kbd; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.kbd->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { + dev = tz_devicemgr->devices.ptr; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.ptr->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { + dev = tz_devicemgr->devices.touch; + ret = tz_devicemgr_create_device(dev, clas, name); + if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) { + inited = true; + tz_devicemgr->devices.touch->ref++; + } + if (dev->created) { + wl_signal_emit(&tz_devicemgr->backend->events.new_input, + dev->input_device); + } + } + + if (inited) { + wl_list_for_each(client_data, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) { + if (client_data->init == false) { + client_data->init = true; + client_data->clas = clas; + } + break; + } + } + } + + return ret; +} + +static int +tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr, + struct wl_resource *resource) +{ + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + struct ds_tizen_input_devicemgr_client *client_data; + struct ds_tizen_input_devicemgr_device *dev; + uint32_t clas = 0; + int i = 0; + bool res; + + ds_inf("Deinit generator."); + wl_list_for_each(client_data, &tz_devicemgr->clients, link) { + if (client_data->resource == resource) { + if (client_data->init == true) { + client_data->init = false; + clas = client_data->clas; + break; + } else { + return ret; + } + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { + dev = tz_devicemgr->devices.kbd; + dev->ref--; + if (dev->ref<= 0) { + dev->ref = 0; + tz_devicemgr_pressed_keys_cleanup(tz_devicemgr); + + if (dev->created) { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) { + dev = tz_devicemgr->devices.ptr; + dev->ref--; + if (dev->ref <= 0) { + dev->ref = 0; + while(dev->mouse.pressed) + { + if (dev->mouse.pressed & (1 << i)) + { + res = tz_devicemgr_generate_mouse_button(dev->input_device, + i + 1, false); + if (!res) break; + dev->mouse.pressed &= ~(1 << i); + } + i++; + if (i >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) break; + } + + if (dev->created) + { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) { + dev = tz_devicemgr->devices.touch; + dev->ref--; + if (dev->ref <= 0) { + dev->ref = 0; + while(dev->touch.pressed) + { + if (dev->touch.pressed & (1 << i)) + { + res = tz_devicemgr_generate_touch_up(dev->input_device, + i); + if (!res) break; + dev->touch.pressed &= ~(1 << i); + } + i++; + if (i >= tz_devicemgr->touch_max_count) break; + } + + if (dev->created) + { + tz_devicemgr_device_close(dev); + dev->created = false; + } + free(dev->name); + dev->name = NULL; + } + } + + return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; +} + +static int +tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name) +{ + struct ds_tizen_input_devicemgr_keymap_data *data; + + if (!wl_list_empty(list)) { + wl_list_for_each(data, list, link) { + if (!strcmp(data->name, name)) { + return data->keycode; + } + } + } + + return 0; +} + +static bool +tz_devicemgr_generate_key(struct ds_input_device *device, int keycode, + int pressed) +{ + struct ds_event_keyboard_key ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_keyboard *kbd; + + kbd = ds_input_device_get_keyboard(device); + if (!kbd) { + ds_err("No ds_keyboard to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.keycode = keycode - 8; + if (pressed) + ds_event.state = WL_KEYBOARD_KEY_STATE_PRESSED; + else + ds_event.state = WL_KEYBOARD_KEY_STATE_RELEASED; + + ds_inf("Generate key. kbd:%p, key:%d, state:%s", kbd, ds_event.keycode, + (ds_event.state == WL_KEYBOARD_KEY_STATE_PRESSED) ? + "PRESSED" : "RELEASED"); + + ds_keyboard_notify_key(kbd, &ds_event); + + return true; +} + +static bool +tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr, + int keycode, bool pressed) +{ + struct ds_tizen_input_devicemgr_key_info *key, *tmp; + + if (pressed) { + key = calloc(1, sizeof(*key)); + if (!key) { + ds_err("Failed to alloc keydata memory.\n"); + return false; + } + key->keycode = keycode; + wl_list_init(&key->link); + wl_list_insert(&tz_devicemgr->devices.kbd->key.pressed, &key->link); + } + else { + wl_list_for_each_safe(key, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { + if (key->keycode == keycode) { + wl_list_remove(&key->link); + free(key); + break; + } + } + } + + ds_inf("Update pressed keys. length: %d, keycode:%d, pressed:%d", + wl_list_length(&tz_devicemgr->devices.kbd->key.pressed), keycode, pressed); + + return true; +} + +static void +tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; + + ds_inf("Clean up the kbd.pressed_keys. length: %d", + wl_list_length(&tz_devicemgr->devices.kbd->key.pressed)); + + wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) { + if (tz_devicemgr->devices.kbd) + tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device, + keydata->keycode, false); + wl_list_remove(&keydata->link); + free(keydata); + } +} + +static void +tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + struct ds_tizen_input_devicemgr_keymap_data *keymap, *tmp; + + ds_inf("Clean up the keymap_list. length: %d", + wl_list_length(&tz_devicemgr->keymap_list)); + + wl_list_for_each_safe(keymap, tmp, &tz_devicemgr->keymap_list, link) { + free(keymap->name); + wl_list_remove(&keymap->link); + free(keymap); + } +} + +static bool +tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y, + uint32_t finger) +{ + struct ds_event_touch_motion ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; + + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_event.x = x; + ds_event.y = y; + ds_inf("Generate touch motion. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); + + wl_signal_emit(&touch->events.motion, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y, + uint32_t finger) +{ + struct ds_event_touch_down ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; + + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_event.x = x; + ds_event.y = y; + ds_inf("Generate touch down. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y); + + wl_signal_emit(&touch->events.down, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger) +{ + struct ds_event_touch_up ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_touch *touch; + + touch = ds_input_device_get_touch(device); + if (!touch) { + ds_err("No ds_touch to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.id = finger; + ds_inf("Generate touch up. touch:%p, id:%d", touch, ds_event.id); + + wl_signal_emit(&touch->events.up, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y) +{ + struct ds_event_pointer_motion ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_pointer *pointer; + + pointer = ds_input_device_get_pointer(device); + if (!pointer) { + ds_err("No ds_pointer to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.delta_x = x; + ds_event.delta_y = y; + ds_inf("Generate mouse motion. pointer:%p, x:%f, y:%f", pointer, ds_event.delta_x, ds_event.delta_y); + + wl_signal_emit(&pointer->events.motion, &ds_event); + + return true; +} + +static bool +tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state) +{ + struct ds_event_pointer_button ds_event; + struct timeval time; + unsigned int timestamp; + struct ds_pointer *pointer; + + pointer = ds_input_device_get_pointer(device); + if (!pointer) { + ds_err("No ds_pointer to notify event"); + return false; + } + + gettimeofday(&time, NULL); + timestamp = time.tv_sec * 1000 + time.tv_usec / 1000; + + ds_event.time_msec = timestamp; + ds_event.button = button; + if (state) + ds_event.state = DS_BUTTON_PRESSED; + else + ds_event.state = DS_BUTTON_RELEASED; + ds_inf("Generate mouse button. pointer:%p, button:%d, state:%s", pointer, ds_event.button, state ? "PRESSED" : "RELEASED"); + + wl_signal_emit(&pointer->events.button, &ds_event); + + return true; +} + +static void +devicemgr_keyboard_grab_iface_enter(struct ds_seat_keyboard_grab *grab, + struct ds_surface *surface, uint32_t keycodes[], + size_t num_keycodes, struct ds_keyboard_modifiers *modifiers) +{ + ds_inf("devicemgr. keyboard_grab_iface_enter"); +} + +static void +devicemgr_keyboard_grab_iface_clear_focus(struct ds_seat_keyboard_grab *grab) +{ + ds_inf("devicemgr. keyboard_grab_iface_clear_focus"); +} + +static void +tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; + + ds_inf("Clean up the blocked keys. length: %d", + wl_list_length(&tz_devicemgr->blocked_keys)); + + wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->blocked_keys, link) { + wl_list_remove(&keydata->link); + free(keydata); + } +} + +static void +devicemgr_keyboard_grab_iface_key(struct ds_seat_keyboard_grab *grab, + uint32_t time_msec, uint32_t key, uint32_t state) +{ + struct ds_tizen_input_devicemgr *devicemgr; + struct ds_tizen_input_devicemgr_key_info *keydata, *tmp; + bool key_blocked = false; + + ds_inf("devicemgr. keyboard_grab_iface_key"); + + devicemgr = ds_seat_keyboard_grab_get_data(grab); + if (!devicemgr->block_resource) { + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + goto finish; + } + else { + wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { + if (keydata->keycode == (int)key) { + wl_list_remove(&keydata->link); + free(keydata); + key_blocked = true; + break; + } + } + if (wl_list_empty(&devicemgr->blocked_keys)) { + tz_devicemgr_ungrab_keyboard(devicemgr); + } + if (key_blocked) { + goto finish; + } + } + } + + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + keydata = calloc(1, sizeof (*keydata)); + if (!keydata) + goto finish; + keydata->keycode = key; + wl_list_init(&keydata->link); + wl_list_insert(&devicemgr->blocked_keys, &keydata->link); + key_blocked = true; + } + else { + if (wl_list_empty(&devicemgr->blocked_keys)) + goto finish; + wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) { + if (keydata->keycode == (int)key) { + wl_list_remove(&keydata->link); + free(keydata); + key_blocked = true; + } + } + } + +finish: + if (!key_blocked) + ds_inf("block key event: (%d %s)\n", key, (state ? "press" : "release")); +} + +static void +devicemgr_modifiers_grab_iface_key(struct ds_seat_keyboard_grab *grab, + struct ds_keyboard_modifiers *modifiers) +{ + ds_inf("devicemgr. modifiers_grab_iface_key"); +} + +static void +devicemgr_cancel_grab_iface_key(struct ds_seat_keyboard_grab *grab) +{ + ds_inf("devicemgr. cancel_grab_iface_key"); +} + +static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface = { + .enter = devicemgr_keyboard_grab_iface_enter, + .clear_focus = devicemgr_keyboard_grab_iface_clear_focus, + .key = devicemgr_keyboard_grab_iface_key, + .modifiers = devicemgr_modifiers_grab_iface_key, + .cancel = devicemgr_cancel_grab_iface_key, +}; + +static void +tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + ds_seat_keyboard_start_grab(tz_devicemgr->seat, tz_devicemgr->grab); +} + +static void +tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + ds_seat_keyboard_end_grab(tz_devicemgr->seat); +} + +static void +tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr) +{ + if (wl_list_empty(&tz_devicemgr->blocked_keys)) + tz_devicemgr_ungrab_keyboard(tz_devicemgr); + + tz_devicemgr->block_resource = NULL; +} + +static bool +devicemgr_add_timer(struct ds_tizen_input_devicemgr *tz_devicemgr, + wl_event_loop_timer_func_t func, int time) +{ + struct wl_event_loop *event_loop; + + event_loop = wl_display_get_event_loop(tz_devicemgr->backend->display); + if (!event_loop) { + ds_err("Failed to get event_loop from display: %p", + tz_devicemgr->backend->display); + return false; + } + + tz_devicemgr->timer = wl_event_loop_add_timer(event_loop, func, + tz_devicemgr); + if (!tz_devicemgr->timer) { + ds_err("Failed to timer"); + return false; + } + wl_event_source_timer_update(tz_devicemgr->timer, time); + + return true; +} + +static int +devicemgr_block_timer(void *data) +{ + struct ds_tizen_input_devicemgr *devicemgr = data; + + tizen_input_device_manager_send_block_expired(devicemgr->block_resource); + + tz_devicemgr_ungrab_keyboard_check(devicemgr); + + wl_event_source_remove(devicemgr->timer); + devicemgr->timer = NULL; + + return 1; +} + +static void +device_manager_handle_block_events(struct wl_client *client, + struct wl_resource *resource, uint32_t serial, uint32_t clas, + uint32_t duration) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + bool res; + + tz_devicemgr = wl_resource_get_user_data(resource); + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_BLOCK)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) { + ds_err("only support keyboard device. (requested: 0x%x)\n", clas); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + if(tz_devicemgr->block_resource) { + ds_err("currently the input system is already blocked\n"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + res = devicemgr_add_timer(tz_devicemgr, devicemgr_block_timer, duration); + if (!res) { + ds_err("Failed to add a timer\n"); + goto finish; + } + + tz_devicemgr_grab_keyboard(tz_devicemgr); + tz_devicemgr->block_resource = resource; + ds_inf("Block events. clas: %d, duration:%d", clas, duration); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + +static void +device_manager_handle_unblock_events(struct wl_client *client, + struct wl_resource *resource, uint32_t serial) +{ + struct ds_tizen_input_devicemgr *tz_devicemgr; + int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES; + + tz_devicemgr = wl_resource_get_user_data(resource); + + if (!tz_devicemgr_check_privilege(tz_devicemgr, client, + TIZEN_PRIV_INPUT_BLOCK)) { + ds_err("No permission to input generate"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION; + goto finish; + } + + if (tz_devicemgr->block_resource != resource) { + ds_err("currently the input system is blocked by another resource"); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER; + goto finish; + } + + tz_devicemgr_ungrab_keyboard_check(tz_devicemgr); + tz_devicemgr->block_resource = NULL; + ds_inf("Unblock events."); + ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE; + + if (tz_devicemgr->timer) { + wl_event_source_remove(tz_devicemgr->timer); + tz_devicemgr->timer = NULL; + } + +finish: + tizen_input_device_manager_send_error(resource, ret); +} + diff --git a/src/input_devicemgr/input_devicemgr.h b/src/input_devicemgr/input_devicemgr.h new file mode 100644 index 0000000..a4428ee --- /dev/null +++ b/src/input_devicemgr/input_devicemgr.h @@ -0,0 +1,78 @@ +#ifndef DS_TIZEN_DEVICEMGR_H +#define DS_TIZEN_DEVICEMGR_H + +#include +#include +#include +#include +#include +#include + +struct ds_tizen_input_devicemgr_device { + char *name; + struct ds_input_device *input_device; + int ref; + + bool created; + + struct { + struct wl_list pressed; + } key; + + struct { + unsigned int pressed; + } touch; + + struct { + unsigned int pressed; + } mouse; +}; + +struct ds_tizen_input_devicemgr { + struct wl_global *global; + struct wl_display *display; + struct ds_backend *backend; + struct ds_seat *seat; + + struct { + struct wl_signal destroy; + } events; + + struct wl_listener new_input; + struct wl_listener backend_destroy; + struct wl_listener seat_destroy; + struct { + struct ds_tizen_input_devicemgr_device *kbd; + struct ds_tizen_input_devicemgr_device *ptr; + struct ds_tizen_input_devicemgr_device *touch; + } devices; + + struct wl_list clients; + + struct wl_list keymap_list; + + struct wl_list blocked_keys; + struct wl_resource *block_resource; + struct wl_event_source *timer; + struct ds_seat_keyboard_grab *grab; + int touch_max_count; + + struct { + uint32_t width; + uint32_t height; + } output; +}; + +struct ds_tizen_input_devicemgr_client { + struct wl_resource *resource; + bool init; + uint32_t clas; + struct wl_list link; // ds_tizen_input_devicemgr::clients +}; + +struct ds_tizen_input_devicemgr_key_info { + int keycode; + struct wl_list link; // ds_tizen_input_devicemgr::pressed_keys; +}; + +#endif diff --git a/src/input_devicemgr/meson.build b/src/input_devicemgr/meson.build new file mode 100644 index 0000000..ea8a94f --- /dev/null +++ b/src/input_devicemgr/meson.build @@ -0,0 +1,32 @@ +libds_tizen_input_devicemgr_files = [ + tizen_security_files, + 'input_devicemgr.c', +] + +libds_tizen_input_devicemgr_deps = [ + deps_libds_tizen, + deps_tizen_security, + dependency('tizen-extension-server', required: true), + dependency('xkbcommon', required: true), +] + +lib_libds_tizen_input_devicemgr = shared_library('ds-tizen-input-devicemgr', libds_tizen_input_devicemgr_files, + dependencies: libds_tizen_input_devicemgr_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +deps_libds_tizen_input_devicemgr = declare_dependency( + link_with: lib_libds_tizen_input_devicemgr, + dependencies: libds_tizen_input_devicemgr_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_input_devicemgr, + version: meson.project_version(), + filebase: 'libds-tizen-input-devicemgr', + name: 'libds-tizen-input-devicemgr', + description: 'tizen input devicemgr extension of libds-tizen for tizen platform', +) diff --git a/src/tbm_server/meson.build b/src/tbm_server/meson.build new file mode 100644 index 0000000..795576a --- /dev/null +++ b/src/tbm_server/meson.build @@ -0,0 +1,32 @@ +libds_tizen_tbm_server_files = [ + 'pixel_format.c', + 'tbm_server.c', +] + +libds_tizen_tbm_server_deps = [ + deps_libds_tizen, + dependency('libdrm', required: true), + dependency('libtbm', required: true), + dependency('wayland-tbm-server', required: true), +] + +lib_libds_tizen_tbm_server = shared_library('ds-tizen-tbm-server', libds_tizen_tbm_server_files, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +deps_libds_tizen_tbm_server = declare_dependency( + link_with: lib_libds_tizen_tbm_server, + dependencies: libds_tizen_tbm_server_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_tbm_server, + version: meson.project_version(), + filebase: 'libds-tizen-tbm-server', + name: 'libds-tizen-tbm-server', + description: 'wayland-tbm extension of libds-tizen for tizen platform', +) diff --git a/src/tbm_server/pixel_format.c b/src/tbm_server/pixel_format.c new file mode 100644 index 0000000..030f211 --- /dev/null +++ b/src/tbm_server/pixel_format.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#include +#include "pixel_format.h" + +#ifdef ARRAY_LENGTH +#undef ARRAY_LENGTH +#endif + +#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) + +struct ds_tbm_format +{ + uint32_t drm_format; + uint32_t tbm_format; +}; + +static const struct ds_tbm_format formats[] = +{ + { + .drm_format = DRM_FORMAT_ARGB8888, + .tbm_format = TBM_FORMAT_ARGB8888, + }, + { + .drm_format = DRM_FORMAT_XRGB8888, + .tbm_format = TBM_FORMAT_XRGB8888, + }, + /* TODO more format */ +}; + +uint32_t +convert_drm_format_to_tbm(uint32_t fmt) +{ + size_t i; + + for (i = 0; i < ARRAY_LENGTH(formats); i++) { + if (formats[i].drm_format == fmt) + return formats[i].tbm_format; + } + + ds_err("DRM format 0x%"PRIX32" has no TBM equivalent", fmt); + + return 0; +} + +uint32_t +convert_tbm_format_to_drm(uint32_t fmt) +{ + size_t i; + + for (i = 0; i < ARRAY_LENGTH(formats); i++) { + if (formats[i].tbm_format == fmt) + return formats[i].drm_format; + } + + ds_err("TBM format 0x%"PRIX32" has no DRM equivalent", fmt); + + return 0; +} diff --git a/src/tbm_server/pixel_format.h b/src/tbm_server/pixel_format.h new file mode 100644 index 0000000..a63d096 --- /dev/null +++ b/src/tbm_server/pixel_format.h @@ -0,0 +1,10 @@ +#ifndef DS_TIZEN_PIXEL_FORMAT_H +#define DS_TIZEN_PIXEL_FORMAT_H + +#include + +uint32_t convert_drm_format_to_tbm(uint32_t fmt); + +uint32_t convert_tbm_format_to_drm(uint32_t fmt); + +#endif diff --git a/src/tbm_server/tbm_server.c b/src/tbm_server/tbm_server.c new file mode 100644 index 0000000..0fd25cd --- /dev/null +++ b/src/tbm_server/tbm_server.c @@ -0,0 +1,268 @@ +#include +#include +#include + +#include + +#include +#include "pixel_format.h" +#include "tbm_server.h" + +static const struct ds_buffer_resource_interface tbm_buffer_resource_iface; +static const struct ds_buffer_interface tbm_client_buffer_iface; + +static void tbm_server_handle_display_destroy(struct wl_listener *listener, + void *data); + +WL_EXPORT struct ds_tbm_server * +ds_tbm_server_create(struct wl_display *display) +{ + struct ds_tbm_server *tbm; + tbm_bufmgr bufmgr; + + tbm = calloc(1, sizeof *tbm); + if (!tbm) + return NULL; + + wl_signal_init(&tbm->events.destroy); + + tbm->wl_tbm = wayland_tbm_server_init(display, NULL, -1, 0); + if (!tbm->wl_tbm) { + goto err_wl_tbm; + } + + bufmgr = wayland_tbm_server_get_bufmgr(tbm->wl_tbm); + if (!bufmgr) { + goto err_bind; + } + + if (!tbm_bufmgr_bind_native_display(bufmgr, (void *)display)) { + goto err_bind; + } + + tbm->display_destroy.notify = tbm_server_handle_display_destroy; + wl_display_add_destroy_listener(display, &tbm->display_destroy); + + ds_buffer_register_resource_interface(&tbm_buffer_resource_iface); + + return tbm; + +err_bind: + wayland_tbm_server_deinit(tbm->wl_tbm); +err_wl_tbm: + free(tbm); + + return NULL; +} + +WL_EXPORT void +ds_tbm_server_add_destroy_listener(struct ds_tbm_server *tbm, + struct wl_listener *listener) +{ + wl_signal_add(&tbm->events.destroy, listener); +} + +WL_EXPORT struct ds_tbm_client_buffer * +ds_tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) +{ + if (ds_buffer->iface != &tbm_client_buffer_iface) + return NULL; + return (struct ds_tbm_client_buffer *)ds_buffer; +} + +WL_EXPORT tbm_surface_h +ds_tbm_client_buffer_get_tbm_surface(struct ds_tbm_client_buffer *buffer) +{ + if (buffer->base.iface != &tbm_client_buffer_iface) + return NULL; + return buffer->surface; +} + +static void +tbm_server_handle_display_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tbm_server *tbm; + + tbm = wl_container_of(listener, tbm, display_destroy); + + wl_signal_emit(&tbm->events.destroy, tbm); + + wayland_tbm_server_deinit(tbm->wl_tbm); + free(tbm); +} + +static void +tbm_client_buffer_handle_release(struct wl_listener *listener, void *data) +{ + struct ds_tbm_client_buffer *buffer; + + buffer = wl_container_of(listener, buffer, buffer_release); + if (buffer->resource) + wl_buffer_send_release(buffer->resource); +} + +static void +tbm_client_buffer_handle_resource_destroy(struct wl_listener *listener, + void *data) +{ + struct ds_tbm_client_buffer *buffer; + + buffer = wl_container_of(listener, buffer, resource_destroy); + + buffer->resource = NULL; + buffer->surface = NULL; + wl_list_remove(&buffer->resource_destroy.link); + wl_list_init(&buffer->resource_destroy.link); + + ds_buffer_drop(&buffer->base); +} + +static struct ds_tbm_client_buffer * +tbm_client_buffer_from_buffer(struct ds_buffer *ds_buffer) +{ + assert(ds_buffer->iface == &tbm_client_buffer_iface); + return (struct ds_tbm_client_buffer *)ds_buffer; +} + +static void +tbm_client_buffer_iface_destroy(struct ds_buffer *ds_buffer) +{ + struct ds_tbm_client_buffer *buffer; + + buffer = tbm_client_buffer_from_buffer(ds_buffer); + + ds_inf("Destroy TBM client buffer(%p)", buffer); + + wl_list_remove(&buffer->resource_destroy.link); + wl_list_remove(&buffer->buffer_release.link); + free(buffer); +} + +static bool +tbm_client_buffer_iface_begin_data_ptr_access(struct ds_buffer *ds_buffer, + enum ds_buffer_data_ptr_access_flag flags, void **data, + uint32_t *format, size_t *stride) +{ + struct ds_tbm_client_buffer *buffer; + tbm_surface_info_s info; + tbm_bo_access_option op = TBM_OPTION_NONE; + int err; + + buffer = tbm_client_buffer_from_buffer(ds_buffer); + + if (flags & DS_BUFFER_DATA_PTR_ACCESS_READ) + op |= TBM_OPTION_READ; + + if (flags & DS_BUFFER_DATA_PTR_ACCESS_WRITE) + op |= TBM_OPTION_WRITE; + + err = tbm_surface_map(buffer->surface, op, &info); + if (err != TBM_SURFACE_ERROR_NONE) { + ds_err("Failed tbm_surface_map()"); + return false; + } + + *format = convert_tbm_format_to_drm(buffer->format); + *stride = info.planes[0].stride; + *data = info.planes[0].ptr; + + return true; +} + +static void +tbm_client_buffer_iface_end_ptr_access(struct ds_buffer *ds_buffer) +{ + struct ds_tbm_client_buffer *buffer; + + buffer = tbm_client_buffer_from_buffer(ds_buffer); + + tbm_surface_unmap(buffer->surface); +} + +static const struct ds_buffer_interface tbm_client_buffer_iface = { + .destroy = tbm_client_buffer_iface_destroy, + .begin_data_ptr_access = tbm_client_buffer_iface_begin_data_ptr_access, + .end_data_ptr_access = tbm_client_buffer_iface_end_ptr_access, +}; + +static struct ds_tbm_client_buffer * +tbm_client_buffer_create(struct wl_resource *resource) +{ + struct ds_tbm_client_buffer *buffer; + tbm_surface_h surface; + int32_t width, height; + + surface = wayland_tbm_server_get_surface(NULL, resource); + if (!surface) { + ds_err("Could not get tbm_surface from wl_resource@%d", + wl_resource_get_id(resource)); + return NULL; + } + + width = tbm_surface_get_width(surface); + height = tbm_surface_get_height(surface); + + buffer = calloc(1, sizeof *buffer); + if (!buffer) + return NULL; + + ds_buffer_init(&buffer->base, &tbm_client_buffer_iface, width, height); + + buffer->resource = resource; + buffer->surface = surface; + buffer->format = tbm_surface_get_format(surface); + + buffer->buffer_release.notify = tbm_client_buffer_handle_release; + ds_buffer_add_release_listener(&buffer->base, &buffer->buffer_release); + + buffer->resource_destroy.notify = + tbm_client_buffer_handle_resource_destroy; + wl_resource_add_destroy_listener(resource, &buffer->resource_destroy); + + ds_inf("TBM client buffer(%p) created", buffer); + + return buffer; +} + +static struct ds_tbm_client_buffer * +tbm_client_buffer_get_or_create(struct wl_resource *resource) +{ + struct ds_tbm_client_buffer *buffer; + struct wl_listener *resource_destroy_listener; + + resource_destroy_listener = wl_resource_get_destroy_listener(resource, + tbm_client_buffer_handle_resource_destroy);; + if (resource_destroy_listener) { + buffer = wl_container_of(resource_destroy_listener, + buffer, resource_destroy); + return buffer; + } + + return tbm_client_buffer_create(resource); +} + +static bool +tbm_buffer_resource_iface_is_instance(struct wl_resource *resource) +{ + return !!wayland_tbm_server_get_surface(NULL, resource); +} + +static struct ds_buffer * +tbm_buffer_resource_iface_from_resource(struct wl_resource *resource) +{ + struct ds_tbm_client_buffer *buffer; + + buffer = tbm_client_buffer_get_or_create(resource); + if (!buffer) { + ds_err("Could not get or create ds_tbm_client_buffer"); + return NULL; + } + + return &buffer->base; +} + +static const struct ds_buffer_resource_interface tbm_buffer_resource_iface = { + .name = "tbm", + .is_instance = tbm_buffer_resource_iface_is_instance, + .from_resource = tbm_buffer_resource_iface_from_resource, +}; diff --git a/src/tbm_server/tbm_server.h b/src/tbm_server/tbm_server.h new file mode 100644 index 0000000..58e391b --- /dev/null +++ b/src/tbm_server/tbm_server.h @@ -0,0 +1,34 @@ +#ifndef DS_TIZEN_TBM_SERVER_H +#define DS_TIZEN_TBM_SERVER_H + +#include +#include +#include +#include + +struct ds_tbm_server +{ + struct wayland_tbm_server *wl_tbm; + + struct wl_listener display_destroy; + + struct { + struct wl_signal destroy; + } events; +}; + +struct ds_tbm_client_buffer +{ + struct ds_buffer base; + + tbm_surface_h surface; + struct wl_resource *resource; + + struct wl_listener buffer_release; + struct wl_listener resource_destroy; + + uint32_t format; + size_t stride; +}; + +#endif diff --git a/tests/test_backend.c b/tests/test_backend.c new file mode 100644 index 0000000..69417b6 --- /dev/null +++ b/tests/test_backend.c @@ -0,0 +1,80 @@ +#include +#include +#include + +#include +#include + +static struct ds_backend * +create_possible_wl_backend(struct wl_display *display) +{ + struct ds_backend *backend; + char wl_name[512]; + + for (int i = 0; i < 5; i++) { + snprintf(wl_name, sizeof wl_name, "wayland-%d", i); + backend = ds_wl_backend_create(display, wl_name); + if (backend) + break; + } + + return backend; +} + +static void +test_wl_backend_create(void) +{ + struct wl_display *display; + struct ds_backend *backend; + + display = wl_display_create(); + + backend = create_possible_wl_backend(display); + assert(backend); + + ds_backend_destroy(backend); +} + +struct test +{ + struct wl_listener backend_destroy; + bool cb_called; +}; + +static void +cb_backend_destroy(struct wl_listener *listener, void *data) +{ + struct test *test; + + test = wl_container_of(listener, test, backend_destroy); + test->cb_called = true; +} + +static void +test_wl_backend_destroy_signal(void) +{ + struct wl_display *display; + struct ds_backend *backend; + struct test test; + + display = wl_display_create(); + + backend = create_possible_wl_backend(display); + assert(backend); + + test.cb_called = false; + test.backend_destroy.notify = cb_backend_destroy; + ds_backend_add_destroy_listener(backend, &test.backend_destroy); + + wl_display_destroy(display); + assert(test.cb_called); +} + +int +main(void) +{ + test_wl_backend_create(); + test_wl_backend_destroy_signal(); + + return 0; +} diff --git a/tests/test_compositor.c b/tests/test_compositor.c new file mode 100644 index 0000000..b5883a5 --- /dev/null +++ b/tests/test_compositor.c @@ -0,0 +1,63 @@ +#include +#include + +#include +#include +#include + +static void +test_compositor_create(void) +{ + struct wl_display *display; + struct ds_compositor *compositor; + + display = wl_display_create(); + compositor = ds_compositor_create(display); + assert(compositor); + + wl_display_destroy(display); +} + +struct test +{ + struct wl_listener compositor_destroy; + bool destroyed; +}; + +static void +cb_compositor_destroy(struct wl_listener *listener, void *data) +{ + struct test *test; + + test = wl_container_of(listener, test, compositor_destroy); + test->destroyed = true; +} + +static void +test_compositor_destroy_signal(void) +{ + struct wl_display *display; + struct ds_compositor *compositor; + struct test test; + + display = wl_display_create(); + compositor = ds_compositor_create(display); + assert(compositor); + + test.destroyed = false; + test.compositor_destroy.notify = cb_compositor_destroy; + ds_compositor_add_destroy_listener(compositor, + &test.compositor_destroy); + + wl_display_destroy(display); + assert(test.destroyed == true); +} + +int +main(void) +{ + test_compositor_create(); + test_compositor_destroy_signal(); + + return 0; +} diff --git a/tests/test_subsurface.c b/tests/test_subsurface.c new file mode 100644 index 0000000..98e830d --- /dev/null +++ b/tests/test_subsurface.c @@ -0,0 +1,211 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +struct server_base +{ + struct wl_display *display; + struct ds_compositor *compositor; + const char *socket; +}; + +const char * +test_server_init(struct server_base *server) +{ + server->display = wl_display_create(); + assert(server->display); + server->compositor = ds_compositor_create(server->display); + assert(server->compositor); + server->socket = wl_display_add_socket_auto(server->display); + assert(server->socket); + + return server->socket; +} + +void +test_server_finish(struct server_base *server) +{ + wl_display_destroy(server->display); +} + +struct client +{ + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_subcompositor *subcompositor; + struct wl_surface *surface; + struct wl_subsurface *subsurface; +}; + +static void +handle_global(void *data, struct wl_registry *registry, uint32_t id, + const char *interface, uint32_t version) +{ + struct client *client = data; + + if (strcmp(interface, "wl_compositor") == 0) { + client->compositor = + wl_registry_bind(registry, id, &wl_compositor_interface, version); + } + else if (strcmp(interface, "wl_subcompositor") == 0) { + client->subcompositor = + wl_registry_bind(registry, id, &wl_subcompositor_interface, version); + } +} + +static const struct wl_registry_listener registry_listener = { + .global = handle_global, +}; + +void +test_client_init(struct client *client, const char *name) +{ + client->display = wl_display_connect(name); + assert(client->display); + client->registry = wl_display_get_registry(client->display); + assert(client->registry); + + wl_registry_add_listener(client->registry, ®istry_listener, client); + + wl_display_roundtrip(client->display); + + assert(client->compositor); + assert(client->subcompositor); +} + +void +test_client_finish(struct client *client) +{ + wl_subcompositor_destroy(client->subcompositor); + wl_compositor_destroy(client->compositor); + wl_registry_destroy(client->registry); + wl_display_disconnect(client->display); +} + +struct test_server +{ + struct server_base base; + bool cb_called; + + struct wl_listener new_surface; + struct wl_listener new_subsurface1; + struct wl_listener new_subsurface2; +}; + +static void +cb_new_subsurface1(struct wl_listener *listener, void *data) +{ + struct ds_subsurface *subsurface = data; + struct test_server *server; + + assert(subsurface); + + server = wl_container_of(listener, server, new_subsurface1); + server->cb_called = true; + wl_display_terminate(server->base.display); +} + +static void +cb_new_subsurface2(struct wl_listener *listener, void *data) +{ + struct ds_subsurface *subsurface = data; + struct test_server *server; + + assert(subsurface); + + server = wl_container_of(listener, server, new_subsurface2); + server->cb_called = true; + wl_display_terminate(server->base.display); +} + +static void +cb_new_surface(struct wl_listener *listener, void *data) +{ + struct ds_surface *surface = data; + struct test_server *server; + + server = wl_container_of(listener, server, new_surface); + if (!server->new_subsurface1.notify) { + server->new_subsurface1.notify = cb_new_subsurface1; + ds_surface_add_new_subsurface_listener(surface, + &server->new_subsurface1); + } + else { + server->new_subsurface2.notify = cb_new_subsurface2; + ds_surface_add_new_subsurface_listener(surface, + &server->new_subsurface2); + } +} + +static void +run_client(const char *name) +{ + struct client client; + + test_client_init(&client, name); + + struct wl_surface *surface = + wl_compositor_create_surface(client.compositor); + + struct wl_surface *child_surface = + wl_compositor_create_surface(client.compositor); + + struct wl_subsurface *subsurface = + wl_subcompositor_get_subsurface(client.subcompositor, + child_surface, surface); + + wl_display_roundtrip(client.display); + + wl_subsurface_destroy(subsurface); + wl_surface_destroy(child_surface); + wl_surface_destroy(surface); + + test_client_finish(&client); +} + +static void +test_subsurface_create(void) +{ + struct test_server server = { + .new_subsurface1 = { .notify = NULL }, + .cb_called = false + }; + pid_t pid; + + const char *socket_name = test_server_init(&server.base); + + pid = fork(); + assert(pid != -1); + + if (pid == 0) { + run_client(socket_name); + exit(0); + } + + server.new_surface.notify = cb_new_surface; + ds_compositor_add_new_surface_listener(server.base.compositor, + &server.new_surface); + + wl_display_run(server.base.display); + + assert(server.cb_called); + + test_server_finish(&server.base); +} + +int +main(void) +{ + test_subsurface_create(); + return 0; +} diff --git a/tests/test_surface.c b/tests/test_surface.c new file mode 100644 index 0000000..eab2b77 --- /dev/null +++ b/tests/test_surface.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +struct server_base +{ + struct wl_display *display; + struct ds_compositor *compositor; + const char *socket; +}; + +void +test_server_init(struct server_base *server) +{ + server->display = wl_display_create(); + assert(server->display); + server->compositor = ds_compositor_create(server->display); + assert(server->compositor); + server->socket = wl_display_add_socket_auto(server->display); + assert(server->socket); +} + +void +test_server_finish(struct server_base *server) +{ + wl_display_destroy(server->display); +} + +struct client +{ + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_surface *surface; +}; + +static void +handle_global(void *data, struct wl_registry *registry, uint32_t id, + const char *interface, uint32_t version) +{ + struct client *client = data; + + if (strcmp(interface, "wl_compositor") == 0) { + client->compositor = + wl_registry_bind(registry, id, &wl_compositor_interface, version); + } +} + +static const struct wl_registry_listener registry_listener = { + .global = handle_global, +}; + +void +test_client_init(struct client *client, const char *name) +{ + client->display = wl_display_connect(name); + assert(client->display); + client->registry = wl_display_get_registry(client->display); + assert(client->registry); + + wl_registry_add_listener(client->registry, ®istry_listener, client); + + wl_display_roundtrip(client->display); + + assert(client->compositor); +} + +void +test_client_finish(struct client *client) +{ + wl_compositor_destroy(client->compositor); + wl_registry_destroy(client->registry); + wl_display_disconnect(client->display); +} + +struct test_server { + struct server_base base; + bool cb_called; + + struct wl_listener new_surface; + struct wl_listener surface_destroy; +}; + +static void +cb_surface_destroy(struct wl_listener *listener, void *data) +{ + struct test_server *server; + + server = wl_container_of(listener, server, surface_destroy); + server->cb_called = true; + wl_display_terminate(server->base.display); +} + +static void +cb_new_surface(struct wl_listener *listener, void *data) +{ + struct ds_surface *surface = data; + struct test_server *server; + + server = wl_container_of(listener, server, new_surface); + server->surface_destroy.notify = cb_surface_destroy; + ds_surface_add_destroy_listener(surface, &server->surface_destroy); +} + +static void +run_client(const char *name) +{ + struct client client; + + test_client_init(&client, name); + + struct wl_surface *surface = + wl_compositor_create_surface(client.compositor); + + wl_display_roundtrip(client.display); + + wl_surface_destroy(surface); + + test_client_finish(&client); +} + +static void +test_surface_create_and_destroy(void) +{ + struct test_server server = { .cb_called = false }; + pid_t pid; + + test_server_init(&server.base); + + pid = fork(); + assert(pid != -1); + + if (pid == 0) { + run_client(server.base.socket); + exit(0); + } + + server.new_surface.notify = cb_new_surface; + ds_compositor_add_new_surface_listener(server.base.compositor, + &server.new_surface); + + wl_display_run(server.base.display); + + assert(server.cb_called); + + test_server_finish(&server.base); +} + +int +main(void) +{ + test_surface_create_and_destroy(); + return 0; +} -- 2.7.4 From f29f6dcedae721cec462af6f1bd8add294a0e585 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 6 Jul 2022 10:54:44 +0900 Subject: [PATCH 15/16] keyrouter: Replace get_keyroutes() with notify_key() Instead of returning key routes list to the compositor, it will deal with keyboard key events on the behalf of the compositor according to keyrouter extension protocol. Change-Id: I6b7085402c6bb5cad0160f356c327af1467f9726 --- include/libds-tizen/keyrouter.h | 60 +++++++++------------------------ src/keyrouter/keyrouter.c | 74 +++++++++++++++++++++++++++++++++++++---- src/keyrouter/keyrouter.h | 27 ++++++++++++++- src/keyrouter/keyrouter_grab.c | 25 +++++++------- 4 files changed, 122 insertions(+), 64 deletions(-) diff --git a/include/libds-tizen/keyrouter.h b/include/libds-tizen/keyrouter.h index bd47b54..1be7944 100644 --- a/include/libds-tizen/keyrouter.h +++ b/include/libds-tizen/keyrouter.h @@ -2,6 +2,8 @@ #define LIBDS_TIZEN_KEYROUTER_H #include +#include +#include #ifdef __cplusplus extern "C" { @@ -13,39 +15,6 @@ extern "C" { struct ds_tizen_keyrouter; /** - * The information of keyroute - */ -struct ds_tizen_keyroute_info -{ - struct wl_client *wl_client; -}; - -/** - * Keyroute mode of keyroutes returned by ds_tizen_keyrouter_get_keyroutes() - * for a given keycode. - */ -enum ds_tizen_keyroute_mode { - /** - * The keycode is not under any keyroute mode. - * The compositor may send a keycode to a focused wayland cliet as usual. - */ - DS_TIZEN_KEYROUTE_MODE_NONE, - /** - * Exclusive mode means that a given keycode is required to be sent - * exclusively to wayland clients of returned keyroutes. So the compositor - * must not send this keycode to any other wayland clients except for - * returned wayland clients. - */ - DS_TIZEN_KEYROUTE_MODE_EXCLUSIVE, - /** - * The keycode is required to be shared with returned wayland clients. - * The compositor must send the keycode not only to returned wayland - * clients, but also to a focused wayland client. - */ - DS_TIZEN_KEYROUTE_MODE_SHARED, -}; - -/** * Creates a ds_tizen_keyrouter. */ struct ds_tizen_keyrouter * @@ -59,18 +28,21 @@ ds_tizen_keyrouter_add_destroy_listener(struct ds_tizen_keyrouter *keyrouter, struct wl_listener *listener); /** - * Gets keyroutes and mode for a given keycode. - * The compositor must send a keycode to returned wayland clients according to - * the mode. The parameter, topmost_client, should be given to determine whether - * the given topmost_client require a keycode exclusively when one of its - * surfaces is on very top of stack. See tizen_keyrouter protocol in - * tizen-extension.xml for more detail. + * Notify the keyrouter that a key has been pressed on the keyboard. + * This will eventually notify a given seat of key events, and if there is + * no destination to be routed, then it sends key events to the focused one + * automatically. So, if you call this, you don't need to call + * ds_seat_keyboard_notify_key() manually unless you want to do something + * differently. + * The parameter, topmost_surface, should be given for the keyrouter to + * determine whether the given topmost_surface require a keycode exclusively + * when the surface is on very top of stack. + * See tizen_keyrouter protocol in tizen-extension.xml for more detail. */ -enum ds_tizen_keyroute_mode -ds_tizen_keyrouter_get_keyroutes(struct ds_tizen_keyrouter *keyrouter, - int keycode, struct wl_client *topmost_client, - struct wl_array *keyroutes); - +void +ds_tizen_keyrouter_notify_key(struct ds_tizen_keyrouter *keyrouter, + struct ds_seat *seat, struct ds_surface *topmost_surface, + uint32_t time_msec, uint32_t key, uint32_t state); #ifdef __cplusplus } #endif diff --git a/src/keyrouter/keyrouter.c b/src/keyrouter/keyrouter.c index 2e825c6..097f4df 100644 --- a/src/keyrouter/keyrouter.c +++ b/src/keyrouter/keyrouter.c @@ -29,6 +29,9 @@ static int keyrouter_client_grab_key(struct keyrouter_client *client, int mode, int keycode); static int keyrouter_client_ungrab_key(struct keyrouter_client *client, int keycode); +static void +keyrouter_seat_broadcast_key(struct ds_seat *seat, struct wl_array *keyroutes, + bool with_focus, uint32_t time_msec, uint32_t keycode, uint32_t state); WL_EXPORT struct ds_tizen_keyrouter * ds_tizen_keyrouter_create(struct wl_display *display) @@ -76,13 +79,45 @@ ds_tizen_keyrouter_add_destroy_listener(struct ds_tizen_keyrouter *keyrouter, wl_signal_add(&keyrouter->events.destroy, listener); } -WL_EXPORT enum ds_tizen_keyroute_mode -ds_tizen_keyrouter_get_keyroutes(struct ds_tizen_keyrouter *keyrouter, - int keycode, struct wl_client *topmost_client, - struct wl_array *keyroutes) +WL_EXPORT void +ds_tizen_keyrouter_notify_key(struct ds_tizen_keyrouter *keyrouter, + struct ds_seat *seat, struct ds_surface *topmost_surface, + uint32_t time_msec, uint32_t keycode, uint32_t state) { - return keyrouter_grab_get_keyroutes(&keyrouter->keygrab, - keycode, topmost_client, keyroutes); + struct wl_client *topmost_wl_client = NULL; + struct wl_resource *surface_resource; + struct wl_array keyroutes; + enum keyroute_mode mode; + + wl_array_init(&keyroutes); + + if (topmost_surface) { + surface_resource = ds_surface_get_wl_resource(topmost_surface); + if (surface_resource) { + topmost_wl_client = wl_resource_get_client( + ds_surface_get_wl_resource(topmost_surface)); + } + } + + mode = keyrouter_grab_get_keyroutes(&keyrouter->keygrab, keycode + 8, + topmost_wl_client, &keyroutes); + + if (mode == KEYROUTE_MODE_EXCLUSIVE) { + keyrouter_seat_broadcast_key(seat, &keyroutes, true, + time_msec, keycode, state); + + goto end; + } + + if (mode == KEYROUTE_MODE_SHARED) { + keyrouter_seat_broadcast_key(seat, &keyroutes, false, + time_msec, keycode, state); + } + + ds_seat_keyboard_notify_key(seat, time_msec, keycode, state); + +end: + wl_array_release(&keyroutes); } static void @@ -424,3 +459,30 @@ keyrouter_client_ungrab_key(struct keyrouter_client *client, int keycode) return TIZEN_KEYROUTER_ERROR_NONE; } + +static void +keyrouter_seat_broadcast_key(struct ds_seat *seat, struct wl_array *keyroutes, + bool with_focus, uint32_t time_msec, uint32_t keycode, uint32_t state) +{ + struct ds_seat_client *seat_client, *focused_client; + struct wl_client **wl_client_ptr; + + focused_client = ds_seat_keyboard_get_focused_client(seat); + + wl_array_for_each(wl_client_ptr, keyroutes) { + seat_client = ds_seat_client_for_wl_client(seat, *wl_client_ptr); + if (!seat_client) { + ds_inf("Could not find ds_seat_client for given wl_client(%p)", + *wl_client_ptr); + continue; + } + + if (seat_client == focused_client) { + if (with_focus) + ds_seat_keyboard_notify_key(seat, time_msec, keycode, state); + } + else { + ds_seat_client_send_key(seat_client, time_msec, keycode, state); + } + } +} diff --git a/src/keyrouter/keyrouter.h b/src/keyrouter/keyrouter.h index bea9ab1..bd3faa9 100644 --- a/src/keyrouter/keyrouter.h +++ b/src/keyrouter/keyrouter.h @@ -9,6 +9,31 @@ #define KEYROUTER_MAX_KEYS 512 +/** + * Keyroute mode of keyroutes returned by keyrouter_grab_get_keyroutes() + * for a given keycode. + */ +enum keyroute_mode { + /** + * The keycode is not under any keyroute mode. + * The compositor may send a keycode to a focused wayland cliet as usual. + */ + KEYROUTE_MODE_NONE, + /** + * Exclusive mode means that a given keycode is required to be sent + * exclusively to wayland clients of returned keyroutes. So the compositor + * must not send this keycode to any other wayland clients except for + * returned wayland clients. + */ + KEYROUTE_MODE_EXCLUSIVE, + /** + * The keycode is required to be shared with returned wayland clients. + * The compositor must send the keycode not only to returned wayland + * clients, but also to a focused wayland client. + */ + KEYROUTE_MODE_SHARED, +}; + struct keyroute_info { struct wl_client *wl_client; @@ -92,7 +117,7 @@ int keyrouter_grab_grab_key(struct keyrouter_grab *keygrab, int mode, void keyrouter_grab_ungrab_key(struct keyrouter_grab *keygrab, int mode, int keycode, struct wl_client *wl_client); -enum ds_tizen_keyroute_mode +enum keyroute_mode keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode, struct wl_client *topmost_client, struct wl_array *keyroutes); diff --git a/src/keyrouter/keyrouter_grab.c b/src/keyrouter/keyrouter_grab.c index fed301b..4f27ea1 100644 --- a/src/keyrouter/keyrouter_grab.c +++ b/src/keyrouter/keyrouter_grab.c @@ -31,7 +31,7 @@ keyrouter_grab_topmost_find(struct keyrouter_grab *keygrab, int keycode, struct wl_client *topmost_client); static bool keyrouter_grab_get_shared_keyroutes(struct keyrouter_grab *keygrab, int keycode, struct wl_array *keyroutes); -static bool keyroutes_add_info(struct wl_array *keyroutes, +static bool keyroutes_add_wl_client(struct wl_array *keyroutes, struct wl_client *wl_client); void @@ -58,7 +58,7 @@ keyrouter_grab_finish(struct keyrouter_grab *keygrab) } } -enum ds_tizen_keyroute_mode +enum keyroute_mode keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode, struct wl_client *topmost_client, struct wl_array *keyroutes) { @@ -82,16 +82,16 @@ keyrouter_grab_get_keyroutes(struct keyrouter_grab *keygrab, int keycode, goto exclusive_out; if (keyrouter_grab_get_shared_keyroutes(keygrab, keycode, keyroutes)) - return DS_TIZEN_KEYROUTE_MODE_SHARED; + return KEYROUTE_MODE_SHARED; none_out: - return DS_TIZEN_KEYROUTE_MODE_NONE; + return KEYROUTE_MODE_NONE; exclusive_out: - if (!keyroutes_add_info(keyroutes, info->wl_client)) + if (!keyroutes_add_wl_client(keyroutes, info->wl_client)) ds_err("Could not add wl_client to keyroutes"); - return DS_TIZEN_KEYROUTE_MODE_EXCLUSIVE; + return KEYROUTE_MODE_EXCLUSIVE; } int @@ -299,7 +299,7 @@ keyrouter_grab_get_shared_keyroutes(struct keyrouter_grab *keygrab, int count = 0; wl_list_for_each(info, list, link) { - if (!keyroutes_add_info(keyroutes, info->wl_client)) { + if (!keyroutes_add_wl_client(keyroutes, info->wl_client)) { ds_err("Could not prepend wl_client to delivery_list"); continue; } @@ -314,16 +314,15 @@ keyrouter_grab_get_shared_keyroutes(struct keyrouter_grab *keygrab, } static bool -keyroutes_add_info(struct wl_array *keyroutes, - struct wl_client *wl_client) +keyroutes_add_wl_client(struct wl_array *keyroutes, struct wl_client *wl_client) { - struct ds_tizen_keyroute_info *info; + struct wl_client **p; - info = wl_array_add(keyroutes, sizeof *info); - if (!info) + p = wl_array_add(keyroutes, sizeof(struct wl_client *)); + if (!p) return false; - info->wl_client = wl_client; + *p = wl_client; return true; } -- 2.7.4 From c1d56f7d059dc0744fc95f35bec1e60ed46cd332 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 7 Jul 2022 19:57:35 +0900 Subject: [PATCH 16/16] remove the test files. This test files are useless. Change-Id: I0528e80430c947e1dfcf92f8b71860188d9d0ec5 --- tests/meson.build | 25 ------ tests/test_backend.c | 80 ------------------ tests/test_compositor.c | 63 --------------- tests/test_subsurface.c | 211 ------------------------------------------------ tests/test_surface.c | 162 ------------------------------------- 5 files changed, 541 deletions(-) delete mode 100644 tests/meson.build delete mode 100644 tests/test_backend.c delete mode 100644 tests/test_compositor.c delete mode 100644 tests/test_subsurface.c delete mode 100644 tests/test_surface.c diff --git a/tests/meson.build b/tests/meson.build deleted file mode 100644 index 324c760..0000000 --- a/tests/meson.build +++ /dev/null @@ -1,25 +0,0 @@ -tests = [ - { 'name': 'test_compositor' }, - { 'name': 'test_backend' }, - { - 'name': 'test_surface', - 'deps': [ dependency('wayland-client') ], - }, - { - 'name': 'test_subsurface', - 'deps': [ dependency('wayland-client') ], - }, -] - -foreach t : tests - t_deps = [ deps_libds_tizen ] - t_deps += t.get('deps', []) - - test('libds-tizen-' + t.get('name'), - executable('libds-tizen-' + t.get('name'), t.get('name') + '.c', - dependencies: t_deps , - include_directories: common_inc, - install: false - ) - ) -endforeach diff --git a/tests/test_backend.c b/tests/test_backend.c deleted file mode 100644 index 69417b6..0000000 --- a/tests/test_backend.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -#include -#include - -static struct ds_backend * -create_possible_wl_backend(struct wl_display *display) -{ - struct ds_backend *backend; - char wl_name[512]; - - for (int i = 0; i < 5; i++) { - snprintf(wl_name, sizeof wl_name, "wayland-%d", i); - backend = ds_wl_backend_create(display, wl_name); - if (backend) - break; - } - - return backend; -} - -static void -test_wl_backend_create(void) -{ - struct wl_display *display; - struct ds_backend *backend; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - ds_backend_destroy(backend); -} - -struct test -{ - struct wl_listener backend_destroy; - bool cb_called; -}; - -static void -cb_backend_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, backend_destroy); - test->cb_called = true; -} - -static void -test_wl_backend_destroy_signal(void) -{ - struct wl_display *display; - struct ds_backend *backend; - struct test test; - - display = wl_display_create(); - - backend = create_possible_wl_backend(display); - assert(backend); - - test.cb_called = false; - test.backend_destroy.notify = cb_backend_destroy; - ds_backend_add_destroy_listener(backend, &test.backend_destroy); - - wl_display_destroy(display); - assert(test.cb_called); -} - -int -main(void) -{ - test_wl_backend_create(); - test_wl_backend_destroy_signal(); - - return 0; -} diff --git a/tests/test_compositor.c b/tests/test_compositor.c deleted file mode 100644 index b5883a5..0000000 --- a/tests/test_compositor.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include -#include -#include - -static void -test_compositor_create(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - wl_display_destroy(display); -} - -struct test -{ - struct wl_listener compositor_destroy; - bool destroyed; -}; - -static void -cb_compositor_destroy(struct wl_listener *listener, void *data) -{ - struct test *test; - - test = wl_container_of(listener, test, compositor_destroy); - test->destroyed = true; -} - -static void -test_compositor_destroy_signal(void) -{ - struct wl_display *display; - struct ds_compositor *compositor; - struct test test; - - display = wl_display_create(); - compositor = ds_compositor_create(display); - assert(compositor); - - test.destroyed = false; - test.compositor_destroy.notify = cb_compositor_destroy; - ds_compositor_add_destroy_listener(compositor, - &test.compositor_destroy); - - wl_display_destroy(display); - assert(test.destroyed == true); -} - -int -main(void) -{ - test_compositor_create(); - test_compositor_destroy_signal(); - - return 0; -} diff --git a/tests/test_subsurface.c b/tests/test_subsurface.c deleted file mode 100644 index 98e830d..0000000 --- a/tests/test_subsurface.c +++ /dev/null @@ -1,211 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -const char * -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); - - return server->socket; -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_subcompositor *subcompositor; - struct wl_surface *surface; - struct wl_subsurface *subsurface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } - else if (strcmp(interface, "wl_subcompositor") == 0) { - client->subcompositor = - wl_registry_bind(registry, id, &wl_subcompositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); - assert(client->subcompositor); -} - -void -test_client_finish(struct client *client) -{ - wl_subcompositor_destroy(client->subcompositor); - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server -{ - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener new_subsurface1; - struct wl_listener new_subsurface2; -}; - -static void -cb_new_subsurface1(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface1); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_subsurface2(struct wl_listener *listener, void *data) -{ - struct ds_subsurface *subsurface = data; - struct test_server *server; - - assert(subsurface); - - server = wl_container_of(listener, server, new_subsurface2); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - if (!server->new_subsurface1.notify) { - server->new_subsurface1.notify = cb_new_subsurface1; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface1); - } - else { - server->new_subsurface2.notify = cb_new_subsurface2; - ds_surface_add_new_subsurface_listener(surface, - &server->new_subsurface2); - } -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - struct wl_surface *child_surface = - wl_compositor_create_surface(client.compositor); - - struct wl_subsurface *subsurface = - wl_subcompositor_get_subsurface(client.subcompositor, - child_surface, surface); - - wl_display_roundtrip(client.display); - - wl_subsurface_destroy(subsurface); - wl_surface_destroy(child_surface); - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_subsurface_create(void) -{ - struct test_server server = { - .new_subsurface1 = { .notify = NULL }, - .cb_called = false - }; - pid_t pid; - - const char *socket_name = test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(socket_name); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_subsurface_create(); - return 0; -} diff --git a/tests/test_surface.c b/tests/test_surface.c deleted file mode 100644 index eab2b77..0000000 --- a/tests/test_surface.c +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct server_base -{ - struct wl_display *display; - struct ds_compositor *compositor; - const char *socket; -}; - -void -test_server_init(struct server_base *server) -{ - server->display = wl_display_create(); - assert(server->display); - server->compositor = ds_compositor_create(server->display); - assert(server->compositor); - server->socket = wl_display_add_socket_auto(server->display); - assert(server->socket); -} - -void -test_server_finish(struct server_base *server) -{ - wl_display_destroy(server->display); -} - -struct client -{ - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_surface *surface; -}; - -static void -handle_global(void *data, struct wl_registry *registry, uint32_t id, - const char *interface, uint32_t version) -{ - struct client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, id, &wl_compositor_interface, version); - } -} - -static const struct wl_registry_listener registry_listener = { - .global = handle_global, -}; - -void -test_client_init(struct client *client, const char *name) -{ - client->display = wl_display_connect(name); - assert(client->display); - client->registry = wl_display_get_registry(client->display); - assert(client->registry); - - wl_registry_add_listener(client->registry, ®istry_listener, client); - - wl_display_roundtrip(client->display); - - assert(client->compositor); -} - -void -test_client_finish(struct client *client) -{ - wl_compositor_destroy(client->compositor); - wl_registry_destroy(client->registry); - wl_display_disconnect(client->display); -} - -struct test_server { - struct server_base base; - bool cb_called; - - struct wl_listener new_surface; - struct wl_listener surface_destroy; -}; - -static void -cb_surface_destroy(struct wl_listener *listener, void *data) -{ - struct test_server *server; - - server = wl_container_of(listener, server, surface_destroy); - server->cb_called = true; - wl_display_terminate(server->base.display); -} - -static void -cb_new_surface(struct wl_listener *listener, void *data) -{ - struct ds_surface *surface = data; - struct test_server *server; - - server = wl_container_of(listener, server, new_surface); - server->surface_destroy.notify = cb_surface_destroy; - ds_surface_add_destroy_listener(surface, &server->surface_destroy); -} - -static void -run_client(const char *name) -{ - struct client client; - - test_client_init(&client, name); - - struct wl_surface *surface = - wl_compositor_create_surface(client.compositor); - - wl_display_roundtrip(client.display); - - wl_surface_destroy(surface); - - test_client_finish(&client); -} - -static void -test_surface_create_and_destroy(void) -{ - struct test_server server = { .cb_called = false }; - pid_t pid; - - test_server_init(&server.base); - - pid = fork(); - assert(pid != -1); - - if (pid == 0) { - run_client(server.base.socket); - exit(0); - } - - server.new_surface.notify = cb_new_surface; - ds_compositor_add_new_surface_listener(server.base.compositor, - &server.new_surface); - - wl_display_run(server.base.display); - - assert(server.cb_called); - - test_server_finish(&server.base); -} - -int -main(void) -{ - test_surface_create_and_destroy(); - return 0; -} -- 2.7.4