From 830f7fb73750c473233518a6956fc9cbd2117401 Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Wed, 8 Jun 2022 16:46:45 +0900 Subject: [PATCH 01/16] seat: move 'grab' related struct definitions to include folder Change-Id: If430058bb6a962ef4e859efb0ec91edf423bfb94 --- include/libds/seat.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ src/seat.h | 70 ++++------------------------------------------- src/seat/seat_keyboard.c | 31 +++++++++++++++++++++ 3 files changed, 107 insertions(+), 65 deletions(-) diff --git a/include/libds/seat.h b/include/libds/seat.h index dbae0ea..e55fc4c 100644 --- a/include/libds/seat.h +++ b/include/libds/seat.h @@ -36,6 +36,55 @@ struct ds_event_seat_keyboard_focus_change struct ds_seat *seat; struct ds_surface *old_surface, *new_surface; }; +struct ds_seat_pointer_grab; + +struct ds_pointer_grab_interface +{ + void (*enter)(struct ds_seat_pointer_grab *grab, + struct ds_surface *surface, double sx, double sy); + void (*clear_focus)(struct ds_seat_pointer_grab *grab); + void (*motion)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, + double sx, double sy); + uint32_t (*button)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, + uint32_t button, enum ds_button_state state); + void (*axis)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, + enum ds_axis_orientation orientation, double value, + int32_t value_discrete, enum ds_axis_source source); + void (*frame)(struct ds_seat_pointer_grab *grab); + void (*cancel)(struct ds_seat_pointer_grab *grab); +}; + +struct ds_seat_keyboard_grab; + +struct ds_keyboard_grab_interface +{ + void (*enter)(struct ds_seat_keyboard_grab *grab, + struct ds_surface *surface, uint32_t keycodes[], + size_t num_keycodes, struct ds_keyboard_modifiers *modifiers); + void (*clear_focus)(struct ds_seat_keyboard_grab *grab); + void (*key)(struct ds_seat_keyboard_grab *grab, uint32_t time_msec, + uint32_t key, uint32_t state); + void (*modifiers)(struct ds_seat_keyboard_grab *grab, + struct ds_keyboard_modifiers *modifiers); + void (*cancel)(struct ds_seat_keyboard_grab *grab); +}; + +struct ds_touch_point; +struct ds_seat_touch_grab; + +struct ds_touch_grab_interface +{ + uint32_t (*down)(struct ds_seat_touch_grab *grab, uint32_t time_msec, + struct ds_touch_point *point); + void (*up)(struct ds_seat_touch_grab *grab, uint32_t time_msec, + struct ds_touch_point *point); + void (*motion)(struct ds_seat_touch_grab *grab, uint32_t time_msec, + struct ds_touch_point *point); + void (*enter)(struct ds_seat_touch_grab *grab, uint32_t time_msec, + struct ds_touch_point *point); + void (*frame)(struct ds_seat_touch_grab *grab); + void (*cancel)(struct ds_seat_touch_grab *grab); +}; struct ds_seat *ds_seat_create(struct wl_display *display, const char *name); @@ -66,6 +115,11 @@ void ds_seat_pointer_notify_axis(struct ds_seat *seat, uint32_t time_msec, void ds_seat_pointer_notify_frame(struct ds_seat *seat); +void ds_seat_pointer_start_grab(struct ds_seat *seat, + struct ds_seat_pointer_grab *grab); + +void ds_seat_pointer_end_grab(struct ds_seat *seat); + void ds_seat_pointer_add_grab_begin_listener(struct ds_seat *seat, struct wl_listener *listener); @@ -87,6 +141,18 @@ void ds_seat_keyboard_notify_modifiers(struct ds_seat *seat, void ds_seat_keyboard_notify_key(struct ds_seat *seat, uint32_t time_msec, uint32_t key, uint32_t state); +struct ds_seat_keyboard_grab *ds_seat_create_keyboard_grab(struct ds_seat *seat, + const struct ds_keyboard_grab_interface *iface, void *data); + +void ds_seat_keyboard_destroy_grab(struct ds_seat_keyboard_grab *grab); + +void *ds_seat_keyboard_grab_get_data(struct ds_seat_keyboard_grab *grab); + +void ds_seat_keyboard_start_grab(struct ds_seat *seat, + struct ds_seat_keyboard_grab *grab); + +void ds_seat_keyboard_end_grab(struct ds_seat *seat); + void ds_seat_keyboard_add_grab_begin_listener(struct ds_seat *seat, struct wl_listener *listener); @@ -111,6 +177,11 @@ void ds_seat_touch_notify_motion(struct ds_seat *seat, uint32_t time_msec, void ds_seat_touch_notify_frame(struct ds_seat *seat); +void ds_seat_touch_start_grab(struct ds_seat *seat, + struct ds_seat_touch_grab *grab); + +void ds_seat_touch_end_grab(struct ds_seat *seat); + void ds_seat_touch_add_grab_start_listener(struct ds_seat *seat, struct wl_listener *listener); diff --git a/src/seat.h b/src/seat.h index 6295647..94275f5 100644 --- a/src/seat.h +++ b/src/seat.h @@ -4,56 +4,7 @@ #include "libds/keyboard.h" #include "libds/seat.h" -struct ds_seat_pointer_grab; - -struct ds_pointer_grab_interface -{ - void (*enter)(struct ds_seat_pointer_grab *grab, - struct ds_surface *surface, double sx, double sy); - void (*clear_focus)(struct ds_seat_pointer_grab *grab); - void (*motion)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, - double sx, double sy); - uint32_t (*button)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, - uint32_t button, enum ds_button_state state); - void (*axis)(struct ds_seat_pointer_grab *grab, uint32_t time_msec, - enum ds_axis_orientation orientation, double value, - int32_t value_discrete, enum ds_axis_source source); - void (*frame)(struct ds_seat_pointer_grab *grab); - void (*cancel)(struct ds_seat_pointer_grab *grab); -}; - -struct ds_seat_keyboard_grab; - -struct ds_keyboard_grab_interface -{ - void (*enter)(struct ds_seat_keyboard_grab *grab, - struct ds_surface *surface, uint32_t keycodes[], - size_t num_keycodes, struct ds_keyboard_modifiers *modifiers); - void (*clear_focus)(struct ds_seat_keyboard_grab *grab); - void (*key)(struct ds_seat_keyboard_grab *grab, uint32_t time_msec, - uint32_t key, uint32_t state); - void (*modifiers)(struct ds_seat_keyboard_grab *grab, - struct ds_keyboard_modifiers *modifiers); - void (*cancel)(struct ds_seat_keyboard_grab *grab); -}; - -struct ds_touch_point; - -struct ds_seat_touch_grab; - -struct ds_touch_grab_interface -{ - uint32_t (*down)(struct ds_seat_touch_grab *grab, uint32_t time_msec, - struct ds_touch_point *point); - void (*up)(struct ds_seat_touch_grab *grab, uint32_t time_msec, - struct ds_touch_point *point); - void (*motion)(struct ds_seat_touch_grab *grab, uint32_t time_msec, - struct ds_touch_point *point); - void (*enter)(struct ds_seat_touch_grab *grab, uint32_t time_msec, - struct ds_touch_point *point); - void (*frame)(struct ds_seat_touch_grab *grab); - void (*cancel)(struct ds_seat_touch_grab *grab); -}; +struct ds_pointer_grab_interface; struct ds_seat_pointer_grab { @@ -62,6 +13,8 @@ struct ds_seat_pointer_grab void *data; }; +struct ds_keyboard_grab_interface; + struct ds_seat_keyboard_grab { const struct ds_keyboard_grab_interface *iface; @@ -69,6 +22,8 @@ struct ds_seat_keyboard_grab void *data; }; +struct ds_touch_grab_interface; + struct ds_seat_touch_grab { const struct ds_touch_grab_interface *iface; @@ -76,11 +31,6 @@ struct ds_seat_touch_grab void *data; }; -void ds_seat_pointer_start_grab(struct ds_seat *seat, - struct ds_seat_pointer_grab *grab); - -void ds_seat_pointer_end_grab(struct ds_seat *seat); - void ds_seat_pointer_enter(struct ds_seat *seat, struct ds_surface *surface, double sx, double sy); @@ -98,11 +48,6 @@ void ds_seat_pointer_send_axis(struct ds_seat *seat, uint32_t time_msec, void ds_seat_pointer_send_frame(struct ds_seat *seat); -void ds_seat_keyboard_start_grab(struct ds_seat *seat, - struct ds_seat_keyboard_grab *grab); - -void ds_seat_keyboard_end_grab(struct ds_seat *seat); - void ds_seat_keyboard_enter(struct ds_seat *seat, struct ds_surface *surface, uint32_t keycodes[], size_t num_keycodes, struct ds_keyboard_modifiers *modifiers); @@ -115,11 +60,6 @@ void ds_seat_keyboard_send_key(struct ds_seat *seat, uint32_t time_msec, void ds_seat_keyboard_send_modifiers(struct ds_seat *seat, struct ds_keyboard_modifiers *modifiers); -void ds_seat_touch_start_grab(struct ds_seat *seat, - struct ds_seat_touch_grab *grab); - -void ds_seat_touch_end_grab(struct ds_seat *seat); - uint32_t ds_seat_touch_send_down(struct ds_seat *seat, struct ds_surface *surface, uint32_t time_msec, int32_t touch_id, double sx, double sy); diff --git a/src/seat/seat_keyboard.c b/src/seat/seat_keyboard.c index 8931a5c..6d6fed6 100644 --- a/src/seat/seat_keyboard.c +++ b/src/seat/seat_keyboard.c @@ -86,6 +86,37 @@ ds_seat_keyboard_start_grab(struct ds_seat *seat, wl_signal_emit(&seat->events.keyboard_grab_begin, grab); } +struct ds_seat_keyboard_grab * +ds_seat_create_keyboard_grab(struct ds_seat *seat, + const struct ds_keyboard_grab_interface *iface, void *data) +{ + struct ds_seat_keyboard_grab *grab; + + grab = calloc(1, sizeof *grab); + if (!grab) + { + return NULL; + } + + grab->iface = iface; + grab->seat = seat; + grab->data = data; + + return grab; +} + +void +ds_seat_keyboard_destroy_grab(struct ds_seat_keyboard_grab *grab) +{ + free(grab); +} + +void * +ds_seat_keyboard_grab_get_data(struct ds_seat_keyboard_grab *grab) +{ + return grab->data; +} + void ds_seat_keyboard_end_grab(struct ds_seat *seat) { -- 2.7.4 From 25af8372d76fc0783b944df9dc73f55c46479e4e Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 23 May 2022 16:50:58 +0900 Subject: [PATCH 02/16] surface: Export functions for surface role This patch exports functions of ds_surface for the compositor to be able to assign a role to ds_surfaces. Change-Id: I8f79bb2a97de290ed304336408d258d91a7c3abc --- include/libds/surface.h | 23 +++++++++++++ src/surface.h | 23 ------------- src/surface/surface.c | 86 ++++++++++++++++++++++++------------------------- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/include/libds/surface.h b/include/libds/surface.h index 9c26cea..3d014dc 100644 --- a/include/libds/surface.h +++ b/include/libds/surface.h @@ -12,6 +12,12 @@ extern "C" { struct ds_surface; +struct ds_surface_role +{ + const char *name; + void (*commit)(struct ds_surface *surface); +}; + typedef bool (*ds_surface_for_each_func_t)(struct ds_surface *surface, int sx, int sy, void *data); @@ -38,6 +44,23 @@ void ds_surface_send_frame_done(struct ds_surface *surface, const struct timespec *when); +struct ds_surface * +ds_surface_from_resource(struct wl_resource *resource); + +bool +ds_surface_set_role(struct ds_surface *surface, + const struct ds_surface_role *role, void *role_data, + struct wl_resource *error_resource, uint32_t error_code); + +const struct ds_surface_role * +ds_surface_get_role(struct ds_surface *surface); + +void * +ds_surface_get_role_data(struct ds_surface *surface); + +void +ds_surface_reset_role_data(struct ds_surface *surface); + #ifdef __cplusplus } #endif diff --git a/src/surface.h b/src/surface.h index 008fb9c..c1cc358 100644 --- a/src/surface.h +++ b/src/surface.h @@ -5,32 +5,9 @@ #include "libds/surface.h" -struct ds_surface_role -{ - const char *name; - void (*commit)(struct ds_surface *surface); -}; - struct ds_surface * ds_surface_create(struct wl_client *client, uint32_t version, uint32_t id); -struct ds_surface * -ds_surface_from_resource(struct wl_resource *resource); - -bool -ds_surface_set_role(struct ds_surface *surface, - const struct ds_surface_role *role, void *role_data, - struct wl_resource *error_resource, uint32_t error_code); - -const struct ds_surface_role * -ds_surface_get_role(struct ds_surface *surface); - -void * -ds_surface_get_role_data(struct ds_surface *surface); - -void -ds_surface_reset_role_data(struct ds_surface *surface); - bool ds_surface_has_buffer(struct ds_surface *surface); diff --git a/src/surface/surface.c b/src/surface/surface.c index 78dc41c..2acb38b 100644 --- a/src/surface/surface.c +++ b/src/surface/surface.c @@ -70,45 +70,7 @@ ds_surface_send_frame_done(struct ds_surface *surface, } } -struct ds_surface * -ds_surface_create(struct wl_client *client, uint32_t version, uint32_t id) -{ - struct ds_surface *surface; - - surface = calloc(1, sizeof *surface); - if (!surface) { - wl_client_post_no_memory(client); - return NULL; - } - - surface->resource = - wl_resource_create(client, &wl_surface_interface, version, id); - if (!surface->resource) { - free(surface); - wl_client_post_no_memory(client); - return NULL; - } - - wl_resource_set_implementation(surface->resource, &surface_impl, - surface, surface_handle_resource_destroy); - - surface_state_init(&surface->current); - surface_state_init(&surface->pending); - - wl_signal_init(&surface->events.commit); - wl_signal_init(&surface->events.destroy); - wl_signal_init(&surface->events.new_subsurface); - - pixman_region32_init(&surface->buffer_damage); - pixman_region32_init(&surface->opaque_region); - pixman_region32_init(&surface->input_region); - - ds_inf("New ds_surface %p (res %p)", surface, surface->resource); - - return surface; -} - -struct ds_surface * +WL_EXPORT struct ds_surface * ds_surface_from_resource(struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &wl_surface_interface, @@ -116,7 +78,7 @@ ds_surface_from_resource(struct wl_resource *resource) return wl_resource_get_user_data(resource); } -bool +WL_EXPORT bool ds_surface_set_role(struct ds_surface *surface, const struct ds_surface_role *role, void *role_data, struct wl_resource *error_resource, uint32_t error_code) @@ -155,24 +117,62 @@ ds_surface_set_role(struct ds_surface *surface, return true; } -const struct ds_surface_role * +WL_EXPORT const struct ds_surface_role * ds_surface_get_role(struct ds_surface *surface) { return surface->role; } -void * +WL_EXPORT void * ds_surface_get_role_data(struct ds_surface *surface) { return surface->role_data; } -void +WL_EXPORT void ds_surface_reset_role_data(struct ds_surface *surface) { surface->role_data = NULL; } +struct ds_surface * +ds_surface_create(struct wl_client *client, uint32_t version, uint32_t id) +{ + struct ds_surface *surface; + + surface = calloc(1, sizeof *surface); + if (!surface) { + wl_client_post_no_memory(client); + return NULL; + } + + surface->resource = + wl_resource_create(client, &wl_surface_interface, version, id); + if (!surface->resource) { + free(surface); + wl_client_post_no_memory(client); + return NULL; + } + + wl_resource_set_implementation(surface->resource, &surface_impl, + surface, surface_handle_resource_destroy); + + surface_state_init(&surface->current); + surface_state_init(&surface->pending); + + wl_signal_init(&surface->events.commit); + wl_signal_init(&surface->events.destroy); + wl_signal_init(&surface->events.new_subsurface); + + pixman_region32_init(&surface->buffer_damage); + pixman_region32_init(&surface->opaque_region); + pixman_region32_init(&surface->input_region); + + ds_inf("New ds_surface %p (res %p)", surface, surface->resource); + + return surface; +} + bool ds_surface_is_ancestor_of(struct ds_surface *surface, struct ds_surface *target_surface) -- 2.7.4 From 61d9d9a89eece4da11bbb2888fb92fd90a5ffb5c Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 21 Jun 2022 10:53:35 +0900 Subject: [PATCH 03/16] add .clang-format Add clang-format option file for coding rules. Run a clang-format command below. # clang-format -i [file] Change-Id: Ib744f0708a7f41d052e1fce869d819b1cdad5d35 --- .clang-format | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fc9ad87 --- /dev/null +++ b/.clang-format @@ -0,0 +1,102 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +# AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BreakBeforeBraces: Linux +BreakBeforeBinaryOperators: None +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: false +BreakStringLiterals: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: true +IndentGotoLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +... -- 2.7.4 From 62d19bf2ea8ef06e5ff1b8c2101ace86ce5b474d Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 24 Jun 2022 09:59:11 +0900 Subject: [PATCH 04/16] remove the unused files These are files for libds-tizen Change-Id: Iea8f14a87cda2d0613c1a29c7cc8025234612a67 --- clients/simple-dpms.c | 239 --------------- examples/pixman-tbm-helper.c | 64 ----- examples/pixman-tbm-helper.h | 13 - examples/tinyds-tdm-dpms.c | 672 ------------------------------------------- 4 files changed, 988 deletions(-) delete mode 100644 clients/simple-dpms.c delete mode 100644 examples/pixman-tbm-helper.c delete mode 100644 examples/pixman-tbm-helper.h delete mode 100644 examples/tinyds-tdm-dpms.c diff --git a/clients/simple-dpms.c b/clients/simple-dpms.c deleted file mode 100644 index 9b4d22c..0000000 --- a/clients/simple-dpms.c +++ /dev/null @@ -1,239 +0,0 @@ -/* -Copyright (C) 2015 - 2016 Samsung Electronics co., Ltd. All Rights Reserved. - -Contact: - SooChan Lim - Changyeon Lee - JunKyeong Kim - Boram Park - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice (including the next -paragraph) shall be included in all copies or substantial portions of the -Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -struct wl_dpms_info { - char *app_name; - - struct wl_display *display; - struct wl_registry *registry; - struct wl_output *output; - struct tizen_dpms_manager *tz_dpms_mng; - int got_dpms_state; -}; - -void -usage(const char *app_name) -{ - printf("usage: %s \n", app_name); - printf("%s output_num option(set1/get0) state\nex)\n", app_name); - printf("%s 1 0 => set dpms_on\n", app_name); - printf("%s 1 3 => set dpms_off\n", app_name); - printf("%s 0 0 => get state\n", app_name); -} - -static struct wl_dpms_info * -_create_wl_dpms_info (void) -{ - struct wl_dpms_info *test_info = NULL; - - test_info = calloc(1, sizeof(struct wl_dpms_info)); - if (test_info == NULL) { - printf("alloc fail"); - return NULL; - } - - return test_info; -} - -static void -_destroy_wl_dpms_info (struct wl_dpms_info *test_info) -{ - if (!test_info) return; - - if (test_info->app_name) - free(test_info->app_name); - if (test_info->tz_dpms_mng) - tizen_dpms_manager_destroy(test_info->tz_dpms_mng); - if (test_info->registry) - wl_registry_destroy(test_info->registry); - if (test_info->display) - wl_display_disconnect(test_info->display); - - free(test_info); -} - -static void -dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) -{ - struct wl_dpms_info *test_info = (struct wl_dpms_info *)data; - printf("dpms_set_state_cb - mode:%d, error:%d\n", mode, error); - test_info->got_dpms_state = 1; -} - -static void -dpms_handle_get_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) -{ - struct wl_dpms_info *test_info = (struct wl_dpms_info *)data; - printf("dpms_get_state_cb - mode:%d, error:%d\n", mode, error); - test_info->got_dpms_state = 1; -} - -static const struct tizen_dpms_manager_listener dpms_listener = { - dpms_handle_set_state, - dpms_handle_get_state -}; - -static void -handle_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) -{ - struct wl_dpms_info *test_info = (struct wl_dpms_info *)data; - - if (strcmp(interface, "wl_output") == 0) { - test_info->output = wl_registry_bind(registry, name, &wl_output_interface, 2); - if (!test_info->output) - printf("bind wl_output fail\n"); - else - printf("bind wl_output\n"); - } else if (strcmp(interface, "tizen_dpms_manager") == 0) { - test_info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); - if (!test_info->tz_dpms_mng) - printf("bind tizen_dpms_manager fail\n"); - else { - tizen_dpms_manager_add_listener(test_info->tz_dpms_mng, &dpms_listener, test_info); - printf("bind tizen_dpms_manager\n"); - } - } -} - -static void -handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - handle_global, - handle_global_remove -}; - -int -main(int argc, char *argv[]) -{ - struct wl_dpms_info *test_info = NULL; - char *opt = NULL; - int option; - char *sta = NULL; - int state = 0; - - test_info = _create_wl_dpms_info(); - if (test_info == NULL) return 0; - - test_info->app_name = strdup(argv[0]); - if (test_info->app_name == NULL) { - printf("alloc fail"); - goto done; - } - if (argc != 3) { - usage(test_info->app_name); - goto done; - } - - opt = strdup(argv[1]); - if (opt == NULL) { - printf("alloc fail"); - goto done; - } - option = opt[0] - '0'; - free(opt); - if (!(option == 0 || option == 1)) { - usage(test_info->app_name); - goto done; - } - - if (option == 1) { - sta = strdup(argv[2]); - if (sta == NULL) { - printf("alloc fail"); - goto done; - } - state = sta [0] - '0'; - free(sta); - if (!(state == 0 || state == 1 || state == 2 || state == 3)) { - usage(test_info->app_name); - goto done; - } - } - - test_info->display = wl_display_connect(NULL); - if (test_info->display == NULL) { - printf("wl_display_connect fail"); - goto done; - } - - test_info->registry = wl_display_get_registry(test_info->display); - if (test_info->registry == NULL) { - printf("wl_display_get_registry fail"); - goto done; - } - - wl_registry_add_listener(test_info->registry, ®istry_listener, test_info); - wl_display_roundtrip(test_info->display); - - if (!test_info->output || !test_info->tz_dpms_mng) { - printf("bind fail\n"); - goto done; - } - - if (option == 1) { - tizen_dpms_manager_set_dpms(test_info->tz_dpms_mng, test_info->output, state); - printf("set dpms %d\n", state); - } else { - tizen_dpms_manager_get_dpms(test_info->tz_dpms_mng, test_info->output); - printf("get dpms\n"); - } - - test_info->got_dpms_state = 0; - while (!test_info->got_dpms_state) { - wl_display_roundtrip(test_info->display); - } - -done: - _destroy_wl_dpms_info(test_info); - - return 0; -} - diff --git a/examples/pixman-tbm-helper.c b/examples/pixman-tbm-helper.c deleted file mode 100644 index 710eceb..0000000 --- a/examples/pixman-tbm-helper.c +++ /dev/null @@ -1,64 +0,0 @@ -#include - -#include "pixman-tbm-helper.h" - -static uint32_t convert_tbm_format_to_pixman(uint32_t fmt); -static void destroy_tbm_pixman_image(pixman_image_t *image, void *data); - -pixman_image_t * -pixman_image_from_tbm_surface(tbm_surface_h surface, - enum ds_buffer_data_ptr_access_flag access_flag) -{ - pixman_image_t *image; - tbm_surface_info_s info; - uint32_t format; - int tbm_access_flag = 0; - int width, height; - int ret; - - width = tbm_surface_get_width(surface); - height = tbm_surface_get_height(surface); - - if (access_flag & DS_BUFFER_DATA_PTR_ACCESS_READ) - tbm_access_flag |= TBM_OPTION_READ; - if (access_flag & DS_BUFFER_DATA_PTR_ACCESS_WRITE) - tbm_access_flag |= TBM_OPTION_WRITE; - - ret = tbm_surface_map(surface, tbm_access_flag, &info); - assert(ret == TBM_SURFACE_ERROR_NONE); - - format = convert_tbm_format_to_pixman(info.format); - image = pixman_image_create_bits(format, width, height, - (uint32_t *)info.planes[0].ptr, - info.planes[0].stride); - assert(image); - - tbm_surface_internal_ref(surface); - - pixman_image_set_destroy_function(image, - destroy_tbm_pixman_image, surface); - - return image; -} - -static void -destroy_tbm_pixman_image(pixman_image_t *image, void *data) -{ - tbm_surface_h surface = data; - - tbm_surface_unmap(surface); - tbm_surface_internal_unref(surface); -} - -static uint32_t -convert_tbm_format_to_pixman(uint32_t fmt) -{ - switch (fmt) { - case TBM_FORMAT_XRGB8888: - return PIXMAN_x8r8g8b8; - case TBM_FORMAT_ARGB8888: - return PIXMAN_a8r8g8b8; - default: - assert(0 && "not reached"); - } -} diff --git a/examples/pixman-tbm-helper.h b/examples/pixman-tbm-helper.h deleted file mode 100644 index bf9bd55..0000000 --- a/examples/pixman-tbm-helper.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef EXAMPLES_PIXMAN_TBM_HELPER_H -#define EXAMPLES_PIXMAN_TBM_HELPER_H - -#include -#include -#include -#include - -pixman_image_t * -pixman_image_from_tbm_surface(tbm_surface_h surface, - enum ds_buffer_data_ptr_access_flag access_flag); - -#endif diff --git a/examples/tinyds-tdm-dpms.c b/examples/tinyds-tdm-dpms.c deleted file mode 100644 index dc32e8f..0000000 --- a/examples/tinyds-tdm-dpms.c +++ /dev/null @@ -1,672 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define USE_TDM_BUFFER_QUEUE - -#ifdef USE_TDM_BUFFER_QUEUE -#include "pixman-tbm-helper.h" -#include "tinyds-tdm-renderer.h" -#else -#include -#endif - -#include "pixman-helper.h" - -#define TINYDS_UNUSED __attribute__((unused)) - -struct tinyds_output -{ - struct tinyds_server *server; - struct ds_output *ds_output; - struct ds_allocator *allocator; -#ifdef USE_TDM_BUFFER_QUEUE - struct tinyds_renderer renderer; - struct ds_tdm_buffer_queue *buffer_queue; - struct wl_listener buffer_queue_acquirable; -#else - struct ds_swapchain *swapchain; -#endif - struct ds_buffer *front_buffer; - - struct wl_listener output_destroy; - struct wl_listener output_frame; - - int width, height; - - bool drawable; - bool damaged; -}; - -struct tinyds_dpms -{ - struct ds_tizen_dpms *ds_dpms; - struct tinyds_server *server; - - struct wl_listener destroy; - struct wl_listener set_dpms; - struct wl_listener get_dpms; -}; - -struct tinyds_server -{ - struct ds_tbm_server *tbm_server; - - struct wl_display *display; - - struct ds_backend *backend; - struct ds_compositor *compositor; - struct ds_xdg_shell *xdg_shell; - - struct tinyds_output *output; - struct tinyds_dpms *dpms; - struct wl_event_source *stdin_source; - - struct wl_list views; - - struct wl_listener new_output; - struct wl_listener new_xdg_surface; -}; - -struct tinyds_view -{ - struct tinyds_server *server; - - struct tinyds_texture *texture; - struct ds_xdg_surface *xdg_surface; - - struct wl_listener xdg_surface_map; - struct wl_listener xdg_surface_unmap; - struct wl_listener xdg_surface_destroy; - struct wl_listener surface_commit; - struct wl_list link; // tinyds_server::views - - int x, y; - bool mapped; -}; - -struct tinyds_server tinyds; - -static bool init_server(struct tinyds_server *server, struct wl_display *display); -static int server_dispatch_stdin(int fd, uint32_t mask, void *data); -static void output_handle_destroy(struct wl_listener *listener, void *data); -static void output_handle_frame(struct wl_listener *listener, void *data); -static void draw_server_with_damage(struct tinyds_server *server); -static void draw_output(struct tinyds_output *output); -static void output_swap_buffer(struct tinyds_output *output, - struct ds_buffer *buffer); -static void view_send_frame_done(struct tinyds_view *view); -#ifdef USE_TDM_BUFFER_QUEUE -static void output_buffer_queue_init(struct tinyds_output *output); -static void output_renderer_init(struct tinyds_output *output); -static void output_draw_with_renderer(struct tinyds_output *output); -#else -static void output_swapchain_init(struct tinyds_output *output, - int width, int height, uint32_t format); -static void output_draw_with_swapchain(struct tinyds_output *output); -static void draw_view(struct tinyds_view *view, pixman_image_t *dst_image); -#endif -static void dpms_handle_destroy(struct wl_listener *listener, void *data); -static void dpms_handle_set_dpms(struct wl_listener *listener, void *data); -static void dpms_handle_get_dpms(struct wl_listener *listener, void *data); - - -int -main(void) -{ - struct tinyds_server *server = &tinyds; - struct wl_display *display; - struct wl_event_loop *loop; - const char *socket; - bool res; - - ds_log_init(DS_INF, NULL); - - display = wl_display_create(); - assert(display); - - res = init_server(server, display); - assert(res); - - socket = wl_display_add_socket_auto(display); - assert(socket); - - ds_backend_start(server->backend); - - setenv("WAYLAND_DISPLAY", socket, true); - - ds_inf("Running Wayland compositor on WAYLAND_DISPLAY=%s", socket); - - loop = wl_display_get_event_loop(display); - server->stdin_source = wl_event_loop_add_fd(loop, STDIN_FILENO, - WL_EVENT_READABLE, server_dispatch_stdin, server); - - wl_display_run(display); - - wl_display_destroy_clients(display); - wl_display_destroy(display); - - return 0; -} - -static void -view_handle_xdg_surface_map(struct wl_listener *listener, - void *data TINYDS_UNUSED) -{ - struct tinyds_view *view; - - view = wl_container_of(listener, view, xdg_surface_map); - view->mapped = true; -} - -static void -view_handle_xdg_surface_unmap(struct wl_listener *listener, - void *data TINYDS_UNUSED) -{ - struct tinyds_view *view; - - view = wl_container_of(listener, view, xdg_surface_unmap); - view->mapped = false; -} - -static void -view_handle_xdg_surface_destroy(struct wl_listener *listener, - void *data TINYDS_UNUSED) -{ - struct tinyds_view *view; - struct tinyds_server *server; - - view = wl_container_of(listener, view, xdg_surface_destroy); - server = view->server; - - wl_list_remove(&view->xdg_surface_destroy.link); - wl_list_remove(&view->xdg_surface_map.link); - wl_list_remove(&view->xdg_surface_unmap.link); - wl_list_remove(&view->surface_commit.link); - wl_list_remove(&view->link); - free(view); - - draw_server_with_damage(server); -} - -static void -view_handle_surface_commit(struct wl_listener *listener, - void *data TINYDS_UNUSED) -{ - struct tinyds_view *view; - - view = wl_container_of(listener, view, surface_commit); - draw_server_with_damage(view->server); -} - -static void -server_new_xdg_surface(struct wl_listener *listener, void *data) -{ - struct tinyds_server *server; - struct tinyds_view *view; - struct ds_xdg_surface *xdg_surface; - - server = wl_container_of(listener, server, new_xdg_surface); - xdg_surface = data; - - ds_inf("New xdg_surface(%p)", (void *)xdg_surface); - - view = calloc(1, sizeof *view); - assert(view); - - view->server = server; - view->xdg_surface = xdg_surface; - - view->xdg_surface_map.notify = view_handle_xdg_surface_map; - ds_xdg_surface_add_map_listener(xdg_surface, - &view->xdg_surface_map); - - view->xdg_surface_unmap.notify = view_handle_xdg_surface_unmap; - ds_xdg_surface_add_unmap_listener(xdg_surface, - &view->xdg_surface_unmap); - - view->xdg_surface_destroy.notify = view_handle_xdg_surface_destroy; - ds_xdg_surface_add_destroy_listener(xdg_surface, - &view->xdg_surface_destroy); - - view->surface_commit.notify = view_handle_surface_commit; - ds_surface_add_commit_listener( - ds_xdg_surface_get_surface(xdg_surface), - &view->surface_commit); - - wl_list_insert(server->views.prev, &view->link); - - view->x = rand() % 1000; - view->y = rand() % 500; -} - -static void -backend_handle_new_output(struct wl_listener *listener, void *data) -{ - struct tinyds_server *server; - struct tinyds_output *output; - struct ds_output *ds_output; - const struct ds_output_mode *mode; - - server = wl_container_of(listener, server, new_output); - ds_output = data; - - ds_inf("New output(%p)", ds_output); - - if (server->output) - return; - - mode = ds_output_get_preferred_mode(ds_output); - ds_output_set_mode(ds_output, mode); - - output = calloc(1, sizeof *output); - if (!output) - return; - - output->server = server; - output->ds_output = ds_output; - output->width = mode->width; - output->height = mode->height; - output->drawable = true; - output->damaged = true; - -#ifdef USE_TDM_BUFFER_QUEUE - output_buffer_queue_init(output); - output_renderer_init(output); -#else - output_swapchain_init(output, mode->width, mode->height, - DRM_FORMAT_XRGB8888); -#endif - - output->output_destroy.notify = output_handle_destroy; - ds_output_add_destroy_listener(ds_output, &output->output_destroy); - - output->output_frame.notify = output_handle_frame; - ds_output_add_frame_listener(ds_output, &output->output_frame); - - server->output = output; - - draw_output(output); -} - -static bool -add_new_dpms(struct tinyds_server *server) -{ - struct tinyds_dpms *dpms; - - dpms = calloc(1, sizeof *dpms); - if (!dpms) - return false; - - dpms->ds_dpms = ds_tizen_dpms_create(server->display); - if (!dpms->ds_dpms) - return false; - - dpms->destroy.notify = dpms_handle_destroy; - ds_tizen_dpms_add_destroy_listener(dpms->ds_dpms, &dpms->destroy); - - dpms->set_dpms.notify = dpms_handle_set_dpms; - ds_tizen_dpms_add_set_dpms_listener(dpms->ds_dpms, &dpms->set_dpms); - - dpms->get_dpms.notify = dpms_handle_get_dpms; - ds_tizen_dpms_add_get_dpms_listener(dpms->ds_dpms, &dpms->get_dpms); - - server->dpms = dpms; - - ds_inf("Dpms (%p) added", dpms); - - return true; -} - -static bool -init_server(struct tinyds_server *server, struct wl_display *display) -{ - server->display = display; - - wl_list_init(&server->views); - - if (wl_display_init_shm(display) != 0) - return false; - - server->backend = ds_tdm_backend_create(display); - if (!server->backend) - return false; - - server->new_output.notify = backend_handle_new_output; - ds_backend_add_new_output_listener(server->backend, - &server->new_output); - - server->compositor = ds_compositor_create(display); - if (!server->compositor) { - ds_backend_destroy(server->backend); - return false; - } - - server->tbm_server = ds_tbm_server_create(display); - if (!server->tbm_server) { - ds_backend_destroy(server->backend); - return false; - } - - server->xdg_shell = ds_xdg_shell_create(display); - if (!server->xdg_shell) { - ds_backend_destroy(server->backend); - return false; - } - - server->new_xdg_surface.notify = server_new_xdg_surface; - ds_xdg_shell_add_new_surface_listener(server->xdg_shell, - &server->new_xdg_surface); - - if (!add_new_dpms(server)) { - ds_backend_destroy(server->backend); - return false; - } - - return true; -} - -static void -output_handle_destroy(struct wl_listener *listener, void *data TINYDS_UNUSED) -{ - struct tinyds_output *output = - wl_container_of(listener, output, output_destroy); - - wl_list_remove(&output->output_destroy.link); - wl_list_remove(&output->output_frame.link); - - if (output->front_buffer) - ds_buffer_unlock(output->front_buffer); - -#ifdef USE_TDM_BUFFER_QUEUE - fini_renderer(&output->renderer); -#else - if (output->swapchain) - ds_swapchain_destroy(output->swapchain); - - if (output->allocator) - ds_allocator_destroy(output->allocator); -#endif - - wl_display_terminate(output->server->display); - - output->server->output = NULL; - - free(output); -} - -static void -output_handle_frame(struct wl_listener *listener, void *data TINYDS_UNUSED) -{ - struct tinyds_output *output = - wl_container_of(listener, output, output_frame); - - output->drawable = true; - draw_output(output); -} - -static void -draw_server_with_damage(struct tinyds_server *server) -{ - server->output->damaged = true; - draw_output(server->output); -} - -#ifdef USE_TDM_BUFFER_QUEUE -static void -output_handle_buffer_queue_acquirable(struct wl_listener *listener, - void *data TINYDS_UNUSED) -{ - struct tinyds_output *output; - struct ds_buffer *buffer; - - output = wl_container_of(listener, output, buffer_queue_acquirable); - - buffer = ds_tdm_buffer_queue_acquire(output->buffer_queue); - assert(buffer); - - output_swap_buffer(output, buffer); -} - -static void -output_buffer_queue_init(struct tinyds_output *output) -{ - struct ds_tdm_output *tdm_output; - - tdm_output = ds_tdm_output_from_output(output->ds_output); - assert(tdm_output); - - output->buffer_queue = ds_tdm_output_get_buffer_queue(tdm_output); - assert(output->buffer_queue); - - output->buffer_queue_acquirable.notify = - output_handle_buffer_queue_acquirable; - ds_tdm_buffer_queue_add_acquirable_listener(output->buffer_queue, - &output->buffer_queue_acquirable); -} - -static void -output_renderer_init(struct tinyds_output *output) -{ - init_renderer(&output->renderer); - - renderer_set_surface_queue(&output->renderer, - ds_tdm_buffer_queue_get_native_queue(output->buffer_queue)); - - renderer_set_bg_color(&output->renderer, 80, 80, 80); -} - -static void -output_draw_with_renderer(struct tinyds_output *output) -{ - struct tinyds_view *view; - - ds_dbg(">> BEGIN UPDATE TEXTURES"); - - wl_list_for_each(view, &output->server->views, link) { - struct ds_buffer *ds_buffer; - struct ds_tbm_client_buffer *tbm_buffer; - tbm_surface_h surface; - - if (!view->mapped) - continue; - - ds_buffer = ds_surface_get_buffer( - ds_xdg_surface_get_surface(view->xdg_surface)); - assert(ds_buffer); - - tbm_buffer = ds_tbm_client_buffer_from_buffer(ds_buffer); - assert(tbm_buffer); - - surface = ds_tbm_client_buffer_get_tbm_surface(tbm_buffer); - - renderer_add_texture(&output->renderer, surface, view->x, view->y); - - view_send_frame_done(view); - } - - ds_dbg("<< END UPDATE TEXTURES"); - - renderer_draw(&output->renderer); - -} -#else -static void -output_swapchain_init(struct tinyds_output *output, - int width, int height, uint32_t format); - -{ - output->allocator = ds_tbm_allocator_create(); - assert(output->allocator); - - output->swapchain = ds_swapchain_create(output->allocator, - width, height, format); - assert(output->swapchain); -} - -static void -output_draw_with_swapchain(struct tinyds_output *output) -{ - struct tinyds_view *view; - struct ds_buffer *output_buffer; - pixman_image_t *output_image; - - output_buffer = ds_swapchain_acquire(output->swapchain, NULL); - if (!output_buffer) - return; - - output_image = pixman_image_from_buffer(output_buffer, - DS_BUFFER_DATA_PTR_ACCESS_WRITE); - if (!output_image) { - ds_buffer_unlock(output_buffer); - return; - } - - pixman_image_fill_color(output_image, 80, 80, 80); - - wl_list_for_each(view, &output->server->views, link) { - if (!view->mapped) - continue; - draw_view(view, output_image); - } - pixman_image_unref(output_image); - - output_swap_buffer(output, output_buffer); -} - -static void -draw_view(struct tinyds_view *view, pixman_image_t *dst_image) -{ - struct ds_buffer *buffer; - pixman_image_t *src_image; - - buffer = ds_surface_get_buffer( - ds_xdg_surface_get_surface(view->xdg_surface)); - if (!buffer) - return; - - src_image = pixman_image_from_buffer(buffer, - DS_BUFFER_DATA_PTR_ACCESS_READ); - pixman_image_composite32(PIXMAN_OP_OVER, - src_image, - NULL, - dst_image, - 0, 0, 0, 0, - view->x, view->y, - pixman_image_get_width(src_image), - pixman_image_get_height(src_image)); - pixman_image_unref(src_image); - - view_send_frame_done(view); -} -#endif - -static void -draw_output(struct tinyds_output *output) -{ - - if (!output->drawable || !output->damaged) - return; - -#ifdef USE_TDM_BUFFER_QUEUE - output_draw_with_renderer(output); -#else - output_draw_with_swapchain(output); -#endif - - output->drawable = false; - output->damaged = false; -} - -static void -output_swap_buffer(struct tinyds_output *output, struct ds_buffer *buffer) -{ - ds_output_attach_buffer(output->ds_output, buffer); - ds_output_commit(output->ds_output); - - if (output->front_buffer) - ds_buffer_unlock(output->front_buffer); - output->front_buffer = buffer; -} - -static void -view_send_frame_done(struct tinyds_view *view) -{ - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - ds_surface_send_frame_done(ds_xdg_surface_get_surface(view->xdg_surface), - &now); -} - -static int -server_dispatch_stdin(int fd, uint32_t mask, void *data) -{ - struct tinyds_server *server = data; - - wl_display_terminate(server->display); - - return 1; -} - -static void -dpms_handle_destroy(struct wl_listener *listener, void *data) -{ - struct tinyds_dpms *dpms; - - dpms = wl_container_of(listener, dpms, destroy); - - ds_inf("Dpms(%p) destroyed", dpms); - - wl_list_remove(&dpms->destroy.link); - wl_list_remove(&dpms->set_dpms.link); - wl_list_remove(&dpms->get_dpms.link); - - free(dpms); -} - -static void -dpms_handle_set_dpms(struct wl_listener *listener, void *data) -{ - struct tinyds_dpms *dpms; - struct ds_tizen_dpms_event *event = data; - - dpms = wl_container_of(listener, dpms, set_dpms); - - ds_inf("Dpms(%p) set dpms : %d", dpms, event->mode); - - //To do - //set dpms mode to output - ds_tizen_dpms_send_set_result(dpms->ds_dpms, event->mode, - DS_TIZEN_DPMS_ERROR_NONE); -} - -static void -dpms_handle_get_dpms(struct wl_listener *listener, void *data) -{ - struct tinyds_dpms *dpms; - - dpms = wl_container_of(listener, dpms, get_dpms); - - ds_inf("Dpms(%p) get dpms", dpms); - - //To do - //get dpms mode from output - ds_tizen_dpms_send_get_result(dpms->ds_dpms, DS_TIZEN_DPMS_MODE_ON, - DS_TIZEN_DPMS_ERROR_NONE); -} \ No newline at end of file -- 2.7.4 From b3758210d15df5a69ce70e22fa35ffd8d25f80d0 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2022 10:32:38 +0900 Subject: [PATCH 05/16] add WL_EXPORT Change-Id: I88c4eecae13f1d260b060364cb71acd067db8116 --- src/backend.c | 4 ++-- src/seat/seat_keyboard.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend.c b/src/backend.c index dee97ca..2cb5cbf 100644 --- a/src/backend.c +++ b/src/backend.c @@ -48,7 +48,7 @@ ds_backend_add_new_input_listener(struct ds_backend *backend, wl_signal_add(&backend->events.new_input, listener); } -void +WL_EXPORT void ds_backend_init(struct ds_backend *backend, struct wl_display *display, const struct ds_backend_interface *iface) @@ -60,7 +60,7 @@ ds_backend_init(struct ds_backend *backend, wl_signal_init(&backend->events.new_input); } -void +WL_EXPORT void ds_backend_finish(struct ds_backend *backend) { wl_signal_emit(&backend->events.destroy, backend); diff --git a/src/seat/seat_keyboard.c b/src/seat/seat_keyboard.c index 6d6fed6..b022163 100644 --- a/src/seat/seat_keyboard.c +++ b/src/seat/seat_keyboard.c @@ -76,7 +76,7 @@ ds_seat_keyboard_add_focus_change_listener(struct ds_seat *seat, wl_signal_add(&seat->keyboard.events.focus_change, listener); } -void +WL_EXPORT void ds_seat_keyboard_start_grab(struct ds_seat *seat, struct ds_seat_keyboard_grab *grab) { @@ -86,7 +86,7 @@ ds_seat_keyboard_start_grab(struct ds_seat *seat, wl_signal_emit(&seat->events.keyboard_grab_begin, grab); } -struct ds_seat_keyboard_grab * +WL_EXPORT struct ds_seat_keyboard_grab * ds_seat_create_keyboard_grab(struct ds_seat *seat, const struct ds_keyboard_grab_interface *iface, void *data) { @@ -105,19 +105,19 @@ ds_seat_create_keyboard_grab(struct ds_seat *seat, return grab; } -void +WL_EXPORT void ds_seat_keyboard_destroy_grab(struct ds_seat_keyboard_grab *grab) { free(grab); } -void * +WL_EXPORT void * ds_seat_keyboard_grab_get_data(struct ds_seat_keyboard_grab *grab) { return grab->data; } -void +WL_EXPORT void ds_seat_keyboard_end_grab(struct ds_seat *seat) { struct ds_seat_keyboard *keyboard = &seat->keyboard; -- 2.7.4 From 205dcfe62b9efa6d34364312bd7ce6cac45ef6f4 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 4 Jul 2022 19:12:59 +0900 Subject: [PATCH 06/16] implement the xdg_shell_v6 It provides the wayland server implementation for zxdg_shell_v6_unstable protocol. Change-Id: I154bba10ba3cd9b7a35f93ac309808a172ee48df --- include/libds/xdg_shell_v6.h | 58 +++++ packaging/libds.spec | 30 +++ src/meson.build | 2 + src/xdg_shell_v6/meson.build | 31 +++ src/xdg_shell_v6/xdg_shell_v6.c | 217 ++++++++++++++++ src/xdg_shell_v6/xdg_shell_v6.h | 189 ++++++++++++++ src/xdg_shell_v6/xdg_surface_v6.c | 493 +++++++++++++++++++++++++++++++++++++ src/xdg_shell_v6/xdg_toplevel_v6.c | 329 +++++++++++++++++++++++++ 8 files changed, 1349 insertions(+) create mode 100644 include/libds/xdg_shell_v6.h create mode 100644 src/xdg_shell_v6/meson.build create mode 100644 src/xdg_shell_v6/xdg_shell_v6.c create mode 100644 src/xdg_shell_v6/xdg_shell_v6.h create mode 100644 src/xdg_shell_v6/xdg_surface_v6.c create mode 100644 src/xdg_shell_v6/xdg_toplevel_v6.c diff --git a/include/libds/xdg_shell_v6.h b/include/libds/xdg_shell_v6.h new file mode 100644 index 0000000..40c9c5a --- /dev/null +++ b/include/libds/xdg_shell_v6.h @@ -0,0 +1,58 @@ +#ifndef LIBDS_XDG_SHELL_V6_H +#define LIBDS_XDG_SHELL_V6_H + +#include +#include + +#include "surface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct ds_xdg_shell_v6; + +struct ds_xdg_surface_v6; + +struct ds_xdg_shell_v6 * +ds_xdg_shell_v6_create(struct wl_display *display); + +void +ds_xdg_shell_v6_add_destroy_listener(struct ds_xdg_shell_v6 *shell, + struct wl_listener *listener); + +void +ds_xdg_shell_v6_add_new_surface_listener(struct ds_xdg_shell_v6 *shell, + struct wl_listener *listener); + +void +ds_xdg_surface_v6_add_destroy_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener); + +void +ds_xdg_surface_v6_add_map_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener); + +void +ds_xdg_surface_v6_add_unmap_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener); + +void +ds_xdg_surface_v6_ping(struct ds_xdg_surface_v6 *surface); + +struct ds_surface * +ds_xdg_surface_v6_get_surface(struct ds_xdg_surface_v6 *surface); + +uint32_t +ds_xdg_toplevel_set_size(struct ds_xdg_surface_v6 *surface, + uint32_t width, uint32_t height); + +uint32_t +ds_xdg_toplevel_set_activated(struct ds_xdg_surface_v6 *surface, + bool activated); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/libds.spec b/packaging/libds.spec index 1a7951e..13d59cf 100644 --- a/packaging/libds.spec +++ b/packaging/libds.spec @@ -11,6 +11,7 @@ BuildRequires: meson BuildRequires: pkgconfig(wayland-server) BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(wayland-protocols) +BuildRequires: pkgconfig(xdg-shell-unstable-v6-server) BuildRequires: pkgconfig(pixman-1) BuildRequires: pkgconfig(libdrm) BuildRequires: pkgconfig(xkbcommon) @@ -28,6 +29,21 @@ Requires: %{name} = %{version}-%{release} %description devel Development package of Wayland Compositor Library +## libds-xdg-shell-v6 +%package xdg-shell-v6 +Summary: Wayland Compositor Library for xdg-shell-v6 +Group: Development/Libraries + +%description xdg-shell-v6 +Wayland Compositor Library for xdg-shell-v6 + +%package xdg-shell-v6-devel +Summary: Wayland Compositor Development package for xdg-shell-v6 +Group: Development/Libraries + +%description xdg-shell-v6-devel +Wayland Compositor Development package for xdg-shell-v6 + %prep %setup -q cp %{SOURCE1001} . @@ -62,3 +78,17 @@ ninja -C builddir install %{_bindir}/input-device-test %{_bindir}/libinput-backend %{_bindir}/ds-simple-shm-shell + +%files xdg-shell-v6 +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-xdg-shell-v6.so.* + +%files xdg-shell-v6-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds/xdg_shell_v6.h +%{_libdir}/pkgconfig/libds-xdg-shell-v6.pc +%{_libdir}/libds-xdg-shell-v6.so diff --git a/src/meson.build b/src/meson.build index b59fda2..7cde232 100644 --- a/src/meson.build +++ b/src/meson.build @@ -99,3 +99,5 @@ pkgconfig.generate(lib_libds, name: meson.project_name(), description: 'Wayland compositor library', ) + +subdir('xdg_shell_v6') diff --git a/src/xdg_shell_v6/meson.build b/src/xdg_shell_v6/meson.build new file mode 100644 index 0000000..55c9b85 --- /dev/null +++ b/src/xdg_shell_v6/meson.build @@ -0,0 +1,31 @@ +libds_xdg_shell_v6_files = [ + 'xdg_shell_v6.c', + 'xdg_surface_v6.c', + 'xdg_toplevel_v6.c', +] + +libds_xdg_shell_v6_deps = [ + dep_libds, + dependency('xdg-shell-unstable-v6-server', required: true), +] + +lib_libds_xdg_shell_v6 = shared_library('ds-xdg-shell-v6', libds_xdg_shell_v6_files, + dependencies: libds_xdg_shell_v6_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +deps_libds_xdg_shell_v6 = declare_dependency( + link_with: lib_libds_xdg_shell_v6, + dependencies: libds_xdg_shell_v6_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_xdg_shell_v6, + version: meson.project_version(), + filebase: 'libds-xdg-shell-v6', + name: 'libds-xdg-shell-v6', + description: 'wayland server implementation of xdg-shel-v6 unstable protocol', +) diff --git a/src/xdg_shell_v6/xdg_shell_v6.c b/src/xdg_shell_v6/xdg_shell_v6.c new file mode 100644 index 0000000..7702d73 --- /dev/null +++ b/src/xdg_shell_v6/xdg_shell_v6.c @@ -0,0 +1,217 @@ +#include +#include +#include + +#include "libds/log.h" +#include "libds/xdg_shell_v6.h" + +#include "xdg_shell_v6.h" + +#define XDG_SHELL_V6_BASE_VERSION 1 +#define XDG_SHELL_V6_PING_TIMEOUT 10000 + +static void xdg_shell_v6_handle_display_destroy(struct wl_listener *listener, + void *data); +static void xdg_shell_v6_bind(struct wl_client *wl_client, void *data, + uint32_t verison, uint32_t id); + +WL_EXPORT struct ds_xdg_shell_v6 * +ds_xdg_shell_v6_create(struct wl_display *display) +{ + struct ds_xdg_shell_v6 *shell; + + shell = calloc(1, sizeof *shell); + if (!shell) { + return NULL; + } + + shell->ping_timeout = XDG_SHELL_V6_PING_TIMEOUT; + + wl_list_init(&shell->clients); + + shell->global = wl_global_create(display, &zxdg_shell_v6_interface, + XDG_SHELL_V6_BASE_VERSION, shell, xdg_shell_v6_bind); + if (!shell->global) { + free(shell); + return NULL; + } + + wl_signal_init(&shell->events.destroy); + wl_signal_init(&shell->events.new_surface); + + shell->display_destroy.notify = xdg_shell_v6_handle_display_destroy; + wl_display_add_destroy_listener(display, &shell->display_destroy); + + ds_inf("Global created: xdg_shell_v6(%p)", shell); + + return shell; +} + +WL_EXPORT void +ds_xdg_shell_v6_add_destroy_listener(struct ds_xdg_shell_v6 *shell, + struct wl_listener *listener) +{ + wl_signal_add(&shell->events.destroy, listener); +} + +void +ds_xdg_shell_v6_add_new_surface_listener(struct ds_xdg_shell_v6 *shell, + struct wl_listener *listener) +{ + wl_signal_add(&shell->events.new_surface, listener); +} + +static void +xdg_shell_v6_handle_display_destroy(struct wl_listener *listener, void *data) +{ + struct ds_xdg_shell_v6 *shell; + + shell = wl_container_of(listener, shell, display_destroy); + + ds_inf("Global destroy: xdg_shell_v6(%p)", shell); + + wl_signal_emit(&shell->events.destroy, shell); + wl_list_remove(&shell->display_destroy.link); + wl_global_destroy(shell->global); + free(shell); +} + +static void +xdg_shell_v6_handle_destroy(struct wl_client *wl_client, + struct wl_resource *resource) +{ + struct ds_xdg_client_v6 *client; + + client = wl_resource_get_user_data(resource); + + if (!wl_list_empty(&client->surfaces)) { + wl_resource_post_error(client->resource, + ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES, + "xdg_shell_v6 was destroyed before children"); + return; + } + + wl_resource_destroy(resource); +} + +static void +xdg_shell_v6_handle_create_positioner(struct wl_client *wl_client, + struct wl_resource *resource, uint32_t id) +{ + // TODO +} + +static void +xdg_shell_v6_handle_get_xdg_surface_v6(struct wl_client *wl_client, + struct wl_resource *resource, uint32_t id, + struct wl_resource *surface_resource) +{ + struct ds_xdg_client_v6 *client; + struct ds_surface *surface; + + client = wl_resource_get_user_data(resource); + surface = ds_surface_from_resource(surface_resource); + create_xdg_surface_v6(client, surface, id); +} + +static void +xdg_shell_v6_handle_pong(struct wl_client *wl_client, + struct wl_resource *resource, uint32_t serial) +{ + struct ds_xdg_client_v6 *client; + + client = wl_resource_get_user_data(resource); + if (client->ping_serial != serial) + return; + + wl_event_source_timer_update(client->ping_timer, 0); + client->ping_serial = 0; +} + +static const struct zxdg_shell_v6_interface xdg_shell_v6_impl = +{ + .destroy = xdg_shell_v6_handle_destroy, + .create_positioner = xdg_shell_v6_handle_create_positioner, + .get_xdg_surface = xdg_shell_v6_handle_get_xdg_surface_v6, + .pong = xdg_shell_v6_handle_pong, +}; + +static void +xdg_client_v6_handle_resource_destroy(struct wl_resource *resource) +{ + struct ds_xdg_client_v6 *client; + struct ds_xdg_surface_v6 *surface, *tmp; + + client = wl_resource_get_user_data(resource); + + wl_list_for_each_safe(surface, tmp, &client->surfaces, link) + destroy_xdg_surface_v6(surface); + + if (client->ping_timer != NULL) + wl_event_source_remove(client->ping_timer); + + wl_list_remove(&client->link); + free(client); +} + +static int +xdg_client_v6_handle_ping_timeout(void *user_data) +{ + struct ds_xdg_client_v6 *client = user_data; + struct ds_xdg_surface_v6 *surface; + + wl_list_for_each(surface, &client->surfaces, link) + wl_signal_emit(&surface->events.ping_timeout, surface); + + client->ping_serial = 0; + + return 1; +} + +static void +xdg_client_v6_init_ping_timer(struct ds_xdg_client_v6 *client) +{ + struct wl_display *display; + struct wl_event_loop *loop; + + display = wl_client_get_display(client->wl_client); + loop = wl_display_get_event_loop(display); + client->ping_timer = wl_event_loop_add_timer(loop, + xdg_client_v6_handle_ping_timeout, client); + if (client->ping_timer == NULL) + wl_client_post_no_memory(client->wl_client); +} + +static void +xdg_shell_v6_bind(struct wl_client *wl_client, void *data, uint32_t version, + uint32_t id) +{ + struct ds_xdg_shell_v6 *shell = data; + struct ds_xdg_client_v6 *client; + + client = calloc(1, sizeof *client); + if (client == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + client->wl_client = wl_client; + client->shell = shell; + + wl_list_init(&client->surfaces); + + client->resource = + wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id); + if (client->resource == NULL) { + free(client); + wl_client_post_no_memory(wl_client); + return; + } + + wl_resource_set_implementation(client->resource, &xdg_shell_v6_impl, client, + xdg_client_v6_handle_resource_destroy); + + wl_list_insert(&shell->clients, &client->link); + + xdg_client_v6_init_ping_timer(client); +} diff --git a/src/xdg_shell_v6/xdg_shell_v6.h b/src/xdg_shell_v6/xdg_shell_v6.h new file mode 100644 index 0000000..ee8de5e --- /dev/null +++ b/src/xdg_shell_v6/xdg_shell_v6.h @@ -0,0 +1,189 @@ +#ifndef DS_XDG_SHELL_V6_H +#define DS_XDG_SHELL_V6_H + +#include +#include + +#include "libds/output.h" + +#include "surface.h" + +enum ds_xdg_surface_v6_role +{ + DS_XDG_SURFACE_V6_ROLE_NONE, + DS_XDG_SURFACE_V6_ROLE_TOPLEVEL, + DS_XDG_SURFACE_V6_ROLE_POPUP, +}; + +struct ds_xdg_shell_v6 +{ + struct wl_global *global; + + struct wl_list clients; + + struct wl_listener display_destroy; + + struct { + struct wl_signal destroy; + struct wl_signal new_surface; + } events; + + uint32_t ping_timeout; +}; + +struct ds_xdg_client_v6 +{ + struct ds_xdg_shell_v6 *shell; + + struct wl_resource *resource; + struct wl_client *wl_client; + struct wl_event_source *ping_timer; + + struct wl_list surfaces; + + struct wl_list link; // ds_xdg_shell_v6::clients + + uint32_t ping_serial; +}; + +struct ds_xdg_toplevle_v6_state +{ + bool maximized, fullscreen, resizing, activated; + uint32_t tiled; + uint32_t width, height; + uint32_t max_width, max_height; + uint32_t min_width, min_height; +}; + +struct ds_xdg_toplevle_v6_configure +{ + bool maximized, fullscreen, resizing, activated; + uint32_t tiled; + uint32_t width, height; +}; + +struct ds_xdg_toplevel_v6_requested +{ + bool maximized, minimized, fullscreen; + struct ds_output *fullscreen_output; + struct wl_listener fullscreen_output_destroy; +}; + +struct ds_xdg_toplevle_v6 +{ + struct wl_resource *resource; + struct ds_xdg_surface_v6 *base; + bool added; + + struct ds_xdg_surface_v6 *parent; + struct wl_listener parent_unmap; + + struct ds_xdg_toplevle_v6_state current, pending; + struct ds_xdg_toplevle_v6_configure scheduled; + struct ds_xdg_toplevel_v6_requested requested; + + char *title; + char *app_id; + + struct { + struct wl_signal request_maximize; + struct wl_signal request_fullscreen; + struct wl_signal request_minimize; + struct wl_signal request_move; + struct wl_signal request_resize; + struct wl_signal request_show_window_menu; + struct wl_signal set_parent; + struct wl_signal set_title; + struct wl_signal set_app_id; + } events; +}; + +struct ds_xdg_popup +{ + +}; + +struct ds_xdg_surface_v6_state +{ + uint32_t configure_serial; + struct { + int x, y; + int width, height; + } geometry; +}; + +struct ds_xdg_surface_v6 +{ + struct ds_xdg_client_v6 *client; + struct ds_surface *ds_surface; + + enum ds_xdg_surface_v6_role role; + + union { + struct ds_xdg_toplevle_v6 *toplevel; + struct ds_xdg_popup *popup; + }; + + struct wl_resource *resource; + + struct wl_event_source *configure_idle; + uint32_t scheduled_serial; + struct wl_list configure_list; + + struct ds_xdg_surface_v6_state current, pending; + + struct wl_list link; // ds_xdg_client_v6::surfaces + + struct { + struct wl_listener surface_destroy; + struct wl_listener surface_commit; + } listener; + + struct { + struct wl_signal destroy; + struct wl_signal ping_timeout; + struct wl_signal new_popup; + struct wl_signal map; + struct wl_signal unmap; + struct wl_signal configure; + struct wl_signal ack_configure; + } events; + + bool added, configured, mapped; +}; + +struct ds_xdg_surface_v6_configure +{ + struct ds_xdg_surface_v6 *surface; + struct wl_list link; + uint32_t serial; + + struct ds_xdg_toplevle_v6_configure *toplevel_configure; +}; + +uint32_t +ds_xdg_surface_v6_schedule_configure(struct ds_xdg_surface_v6 *surface); + +struct ds_xdg_surface_v6 * +create_xdg_surface_v6(struct ds_xdg_client_v6 *client, struct ds_surface *surface, + uint32_t id); + +void destroy_xdg_surface_v6(struct ds_xdg_surface_v6 *surface); + +void +reset_xdg_surface_v6(struct ds_xdg_surface_v6 *surface); + +void +create_xdg_toplevel_v6(struct ds_xdg_surface_v6 *surface, uint32_t id); + +void +handle_xdg_surface_v6_commit(struct ds_surface *ds_surface); + +void +handle_xdg_surface_v6_toplevel_committed(struct ds_xdg_surface_v6 *surface); + +void +send_xdg_toplevel_v6_configure(struct ds_xdg_surface_v6 *surface, + struct ds_xdg_surface_v6_configure *configure); + +#endif diff --git a/src/xdg_shell_v6/xdg_surface_v6.c b/src/xdg_shell_v6/xdg_surface_v6.c new file mode 100644 index 0000000..69ab595 --- /dev/null +++ b/src/xdg_shell_v6/xdg_surface_v6.c @@ -0,0 +1,493 @@ +#include +#include + +#include "libds/log.h" + +#include "xdg_shell_v6.h" + +static const struct zxdg_surface_v6_interface xdg_surface_v6_impl; + +static void xdg_surface_v6_handle_surface_destroy(struct wl_listener *listener, + void *data); +static void xdg_surface_v6_handle_surface_commit(struct wl_listener *listener, + void *data); +static void xdg_surface_v6_handle_resource_destroy(struct wl_resource *resource); +static void xdg_surface_v6_configure_destroy(struct ds_xdg_surface_v6_configure *configure); +static void surface_send_configure(void *user_data); + +void +ds_xdg_surface_v6_add_destroy_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener) +{ + wl_signal_add(&surface->events.destroy, listener); +} + +WL_EXPORT void +ds_xdg_surface_v6_add_map_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener) +{ + wl_signal_add(&surface->events.map, listener); +} + +WL_EXPORT void +ds_xdg_surface_v6_add_unmap_listener(struct ds_xdg_surface_v6 *surface, + struct wl_listener *listener) +{ + wl_signal_add(&surface->events.unmap, listener); +} + +struct ds_surface * +ds_xdg_surface_v6_get_surface(struct ds_xdg_surface_v6 *surface) +{ + return surface->ds_surface; +} + +struct ds_xdg_surface_v6 * +create_xdg_surface_v6(struct ds_xdg_client_v6 *client, struct ds_surface *ds_surface, + uint32_t id) +{ + struct ds_xdg_surface_v6 *surface; + + surface = calloc(1, sizeof *surface); + if (!surface) { + wl_client_post_no_memory(client->wl_client); + return NULL; + } + + surface->client = client; + surface->role = DS_XDG_SURFACE_V6_ROLE_NONE; + surface->ds_surface = ds_surface; + surface->resource = wl_resource_create(client->wl_client, + &zxdg_surface_v6_interface, wl_resource_get_version(client->resource), + id); + if (!surface->resource) { + free(surface); + wl_client_post_no_memory(client->wl_client); + return NULL; + } + + if (ds_surface_has_buffer(surface->ds_surface)) { + wl_resource_destroy(surface->resource); + free(surface); + wl_resource_post_error(client->resource, + ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, + "xdg_surface_v6 must not have a buffer at creation"); + return NULL; + } + + wl_list_init(&surface->configure_list); + + wl_signal_init(&surface->events.destroy); + wl_signal_init(&surface->events.ping_timeout); + wl_signal_init(&surface->events.new_popup); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); + wl_signal_init(&surface->events.configure); + wl_signal_init(&surface->events.ack_configure); + + surface->listener.surface_destroy.notify = + xdg_surface_v6_handle_surface_destroy; + ds_surface_add_destroy_listener(ds_surface, + &surface->listener.surface_destroy); + + surface->listener.surface_commit.notify = + xdg_surface_v6_handle_surface_commit; + ds_surface_add_commit_listener(ds_surface, + &surface->listener.surface_commit); + + wl_resource_set_implementation(surface->resource, &xdg_surface_v6_impl, + surface, xdg_surface_v6_handle_resource_destroy); + + wl_list_insert(&client->surfaces, &surface->link); + + ds_inf("New xdg_surface_v6 %p (res %p)", surface, surface->resource); + + return surface; +} + +void +unmap_xdg_surface_v6(struct ds_xdg_surface_v6 *surface) +{ + struct ds_xdg_surface_v6_configure *configure, *tmp; + + // TODO handle popup + + if (surface->mapped) + wl_signal_emit(&surface->events.unmap, surface); + + switch (surface->role) { + case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: + if (surface->toplevel->parent) { + wl_list_remove(&surface->toplevel->parent_unmap.link); + surface->toplevel->parent = NULL; + } + free(surface->toplevel->title); + surface->toplevel->title = NULL; + free(surface->toplevel->app_id); + surface->toplevel->app_id = NULL; + break; + case DS_XDG_SURFACE_V6_ROLE_POPUP: + // TODO + break; + case DS_XDG_SURFACE_V6_ROLE_NONE: + assert(false && "not reached"); + } + + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) + xdg_surface_v6_configure_destroy(configure); + + if (surface->configure_idle) { + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + } + + surface->configured = false; + surface->mapped = false; +} + +void +reset_xdg_surface_v6(struct ds_xdg_surface_v6 *surface) +{ + struct ds_xdg_toplevel_v6_requested *req; + + if (surface->role != DS_XDG_SURFACE_V6_ROLE_NONE) + unmap_xdg_surface_v6(surface); + + if (surface->added) { + wl_signal_emit(&surface->events.destroy, surface); + surface->added = false; + } + + switch (surface->role) { + case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: + wl_resource_set_user_data(surface->toplevel->resource, NULL); + surface->toplevel->resource = NULL; + req = &surface->toplevel->requested; + if (req->fullscreen_output) + wl_list_remove(&req->fullscreen_output_destroy.link); + free(surface->toplevel); + surface->toplevel = NULL; + break; + case DS_XDG_SURFACE_V6_ROLE_POPUP: + // TODO + break; + case DS_XDG_SURFACE_V6_ROLE_NONE: + // This space is intentionally left blank + break; + } + + surface->role = DS_XDG_SURFACE_V6_ROLE_NONE; +} + +void +destroy_xdg_surface_v6(struct ds_xdg_surface_v6 *surface) +{ + reset_xdg_surface_v6(surface); + + wl_resource_set_user_data(surface->resource, NULL); + + ds_surface_reset_role_data(surface->ds_surface); + + wl_list_remove(&surface->link); + wl_list_remove(&surface->listener.surface_destroy.link); + wl_list_remove(&surface->listener.surface_commit.link); + + free(surface); +} + +void +handle_xdg_surface_v6_commit(struct ds_surface *ds_surface) +{ + struct ds_xdg_surface_v6 *surface; + + surface = ds_surface_get_role_data(ds_surface); + surface->current = surface->pending; + + switch (surface->role) { + case DS_XDG_SURFACE_V6_ROLE_NONE: + // inert toplevel or popup + break; + case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: + handle_xdg_surface_v6_toplevel_committed(surface); + // TODO + break; + case DS_XDG_SURFACE_V6_ROLE_POPUP: + // TODO + break; + } + + if (!surface->added) { + surface->added = true; + wl_signal_emit(&surface->client->shell->events.new_surface, surface); + } + + if (surface->configured && + ds_surface_has_buffer(surface->ds_surface) && + !surface->mapped) { + surface->mapped = true; + wl_signal_emit(&surface->events.map, surface); + } +} + +void handle_xdg_surface_v6_precommit(struct ds_surface *ds_surface) +{ + struct ds_xdg_surface_v6 *surface; + + surface = ds_surface_get_role_data(ds_surface); + + // TODO + (void)surface; +} + +uint32_t +ds_xdg_surface_v6_schedule_configure(struct ds_xdg_surface_v6 *surface) +{ + struct wl_display *display; + struct wl_event_loop *loop; + + display = wl_client_get_display(surface->client->wl_client); + loop = wl_display_get_event_loop(display); + + if (!surface->configure_idle) { + surface->scheduled_serial = wl_display_next_serial(display); + surface->configure_idle = wl_event_loop_add_idle(loop, + surface_send_configure, surface); + if (!surface->configure_idle) + wl_client_post_no_memory(surface->client->wl_client); + } + + return surface->scheduled_serial; +} + +void +ds_xdg_surface_v6_ping(struct ds_xdg_surface_v6 *surface) +{ + struct wl_display *display; + + display = wl_client_get_display(surface->client->wl_client); + + surface->client->ping_serial = wl_display_next_serial(display); + zxdg_shell_v6_send_ping(surface->resource, surface->client->ping_serial); +} + +static void +xdg_surface_v6_handle_surface_destroy(struct wl_listener *listener, void *data) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_container_of(listener, surface, listener.surface_destroy); + destroy_xdg_surface_v6(surface); +} + +static void +xdg_surface_v6_handle_surface_commit(struct wl_listener *listener, void *data) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_container_of(listener, surface, listener.surface_commit); + + if (ds_surface_has_buffer(surface->ds_surface) && + !surface->configured) { + wl_resource_post_error(surface->resource, + ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, + "xdg_surface_v6 has never been configured"); + return; + } + + if (!ds_surface_get_role(surface->ds_surface)) { + wl_resource_post_error(surface->resource, + ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, + "xdg_surface_v6 must have a role"); + return; + } +} + +static void +xdg_surface_v6_handle_resource_destroy(struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + if (!surface) + return; + + destroy_xdg_surface_v6(surface); +} + +static void +xdg_surface_v6_configure_destroy(struct ds_xdg_surface_v6_configure *configure) +{ + wl_list_remove(&configure->link); + free(configure->toplevel_configure); + free(configure); +} + +static void +xdg_surface_v6_handle_destroy(struct wl_client *client, + struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + + if (surface->role != DS_XDG_SURFACE_V6_ROLE_NONE) { + ds_err("Tried to destroy an xdg_surface_v6 before its role object"); + return; + } + + wl_resource_destroy(resource); +} + +static void +xdg_surface_v6_handle_get_toplevel(struct wl_client *client, + struct wl_resource *resource, uint32_t id) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + create_xdg_toplevel_v6(surface, id); +} + +static void +xdg_surface_v6_handle_get_popup(struct wl_client *client, + struct wl_resource *resource, uint32_t id, + struct wl_resource *parent_resource, + struct wl_resource *positioner_resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + + // TODO + (void)surface; +} + +static void +xdg_surface_v6_handle_ack_configure(struct wl_client *client, + struct wl_resource *resource, uint32_t serial) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + + if (surface->role == DS_XDG_SURFACE_V6_ROLE_NONE) { + wl_resource_post_error(surface->resource, + ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, + "xdg_surface_v6 must have a role"); + return; + } + + bool found = false; + struct ds_xdg_surface_v6_configure *configure, *tmp; + wl_list_for_each(configure, &surface->configure_list, link) { + if (configure->serial == serial) { + found = true; + break; + } + } + + if (!found) { + wl_resource_post_error(surface->client->resource, + ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE, + "wrong configure serial: %u", serial); + return; + } + + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + if (configure->serial == serial) + break; + + wl_signal_emit(&surface->events.ack_configure, configure); + xdg_surface_v6_configure_destroy(configure); + } + + switch (surface->role) { + case DS_XDG_SURFACE_V6_ROLE_NONE: + assert(0 && "not reached"); + break; + case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: + // TODO + break; + case DS_XDG_SURFACE_V6_ROLE_POPUP: + break; + } + + surface->configured = true; + surface->pending.configure_serial = serial; + + wl_signal_emit(&surface->events.ack_configure, configure); + xdg_surface_v6_configure_destroy(configure); +} + +static void +xdg_surface_v6_handle_set_window_geometry(struct wl_client *client, + struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + + if (surface->role == DS_XDG_SURFACE_V6_ROLE_NONE) { + wl_resource_post_error(surface->resource, + ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED, + "xdg_surface_v6 must have a role"); + return; + } + + if (width <= 0 || height <= 0) { + ds_err("Client tried to set invalid geometry"); + wl_resource_post_error(resource, -1, + "Tried to set invalid xdg_surface_v6 geometry"); + return; + } + + surface->pending.geometry.x = x; + surface->pending.geometry.y = y; + surface->pending.geometry.width = width; + surface->pending.geometry.height = height; +} + +static const struct zxdg_surface_v6_interface xdg_surface_v6_impl = +{ + .destroy = xdg_surface_v6_handle_destroy, + .get_toplevel = xdg_surface_v6_handle_get_toplevel, + .get_popup = xdg_surface_v6_handle_get_popup, + .ack_configure = xdg_surface_v6_handle_ack_configure, + .set_window_geometry = xdg_surface_v6_handle_set_window_geometry, +}; + +static void +surface_send_configure(void *user_data) +{ + struct ds_xdg_surface_v6 *surface; + struct ds_xdg_surface_v6_configure *configure; + + surface = user_data; + surface->configure_idle = NULL; + + configure = calloc(1, sizeof *configure); + if (!configure) { + wl_client_post_no_memory(surface->client->wl_client); + return; + } + + wl_list_insert(surface->configure_list.prev, &configure->link); + configure->serial = surface->scheduled_serial; + configure->surface = surface; + + switch (surface->role) { + case DS_XDG_SURFACE_V6_ROLE_NONE: + assert(0 && "not reached"); + break; + case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: + send_xdg_toplevel_v6_configure(surface, configure); + break; + case DS_XDG_SURFACE_V6_ROLE_POPUP: + break; + } + + wl_signal_emit(&surface->events.configure, configure); + + zxdg_surface_v6_send_configure(surface->resource, configure->serial); +} diff --git a/src/xdg_shell_v6/xdg_toplevel_v6.c b/src/xdg_shell_v6/xdg_toplevel_v6.c new file mode 100644 index 0000000..463b65a --- /dev/null +++ b/src/xdg_shell_v6/xdg_toplevel_v6.c @@ -0,0 +1,329 @@ +#include +#include +#include + +#include "xdg_shell_v6.h" + +static const struct ds_surface_role xdg_toplevel_v6_surface_role = +{ + .name = "xdg_toplevel_v6", + .commit = handle_xdg_surface_v6_commit, +}; + +static const struct zxdg_toplevel_v6_interface xdg_toplevel_v6_impl; + +static void xdg_toplevel_v6_handle_resource_destroy(struct wl_resource *resource); + +void +create_xdg_toplevel_v6(struct ds_xdg_surface_v6 *surface, uint32_t id) +{ + if (!ds_surface_set_role(surface->ds_surface, &xdg_toplevel_v6_surface_role, + surface, surface->resource, ZXDG_SHELL_V6_ERROR_ROLE)) + return; + + if (surface->role != DS_XDG_SURFACE_V6_ROLE_NONE) { + wl_resource_post_error(surface->resource, + ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED, + "xdg_surface_v6 has already been constructed"); + return; + } + + assert(surface->toplevel == NULL); + + surface->toplevel = calloc(1, sizeof *surface->toplevel); + if (!surface->toplevel) { + wl_resource_post_no_memory(surface->resource); + return; + } + + surface->toplevel->base = surface; + + wl_signal_init(&surface->toplevel->events.request_maximize); + wl_signal_init(&surface->toplevel->events.request_fullscreen); + wl_signal_init(&surface->toplevel->events.request_minimize); + wl_signal_init(&surface->toplevel->events.request_move); + wl_signal_init(&surface->toplevel->events.request_resize); + wl_signal_init(&surface->toplevel->events.request_show_window_menu); + wl_signal_init(&surface->toplevel->events.set_parent); + wl_signal_init(&surface->toplevel->events.set_title); + wl_signal_init(&surface->toplevel->events.set_app_id); + + surface->toplevel->resource = wl_resource_create( + surface->client->wl_client, &zxdg_toplevel_v6_interface, + wl_resource_get_version(surface->resource), id); + if (!surface->toplevel->resource) { + free(surface->toplevel); + wl_resource_post_no_memory(surface->resource); + return; + } + + wl_resource_set_implementation(surface->toplevel->resource, + &xdg_toplevel_v6_impl, surface, + xdg_toplevel_v6_handle_resource_destroy); + + surface->role = DS_XDG_SURFACE_V6_ROLE_TOPLEVEL; +} + +void +handle_xdg_surface_v6_toplevel_committed(struct ds_xdg_surface_v6 *surface) +{ + if (!surface->toplevel->added) { + ds_xdg_surface_v6_schedule_configure(surface); + surface->toplevel->added = true; + return; + } + + surface->toplevel->current = surface->toplevel->pending; +} + +void +send_xdg_toplevel_v6_configure(struct ds_xdg_surface_v6 *surface, + struct ds_xdg_surface_v6_configure *configure) +{ + struct wl_array states; + uint32_t width, height; + + configure->toplevel_configure = + malloc(sizeof *configure->toplevel_configure); + if (!configure->toplevel_configure) { + wl_resource_post_no_memory(surface->toplevel->resource); + return; + } + + *configure->toplevel_configure = surface->toplevel->scheduled; + + wl_array_init(&states); + if (surface->toplevel->scheduled.maximized) { + uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); + if (!s) + goto error_out; + *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; + } + + if (surface->toplevel->scheduled.fullscreen) { + uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); + if (!s) + goto error_out; + *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; + } + + if (surface->toplevel->scheduled.resizing) { + uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); + if (!s) + goto error_out; + *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; + } + + if (surface->toplevel->scheduled.activated) { + uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); + if (!s) + goto error_out; + *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; + } + + if (surface->toplevel->scheduled.tiled) { + ;;; + // TODO + } + + width = surface->toplevel->scheduled.width; + height = surface->toplevel->scheduled.height; + + zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, + &states); + wl_array_release(&states); + + return; + +error_out: + wl_array_release(&states); + wl_resource_post_no_memory(surface->toplevel->resource); +} + +void +destroy_xdg_toplevel_v6(struct ds_xdg_surface_v6 *xdg_surface_v6) +{ + reset_xdg_surface_v6(xdg_surface_v6); +} + +static void +xdg_toplevel_v6_handle_destroy(struct wl_client *client, + struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static void +xdg_toplevel_v6_handle_set_parent(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *parent_resource) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_set_title(struct wl_client *client, + struct wl_resource *resource, const char *title) +{ + struct ds_xdg_surface_v6 *surface; + char *tmp; + + surface = wl_resource_get_user_data(resource); + tmp = strdup(title); + if (!tmp) { + wl_resource_post_no_memory(resource); + return; + } + + if (surface->toplevel->title) + free(surface->toplevel->title); + + surface->toplevel->title = tmp; + wl_signal_emit(&surface->toplevel->events.set_title, surface); +} + +static void +xdg_toplevel_v6_handle_set_app_id(struct wl_client *client, + struct wl_resource *resource, const char *app_id) +{ + struct ds_xdg_surface_v6 *surface; + char *tmp; + + surface = wl_resource_get_user_data(resource); + tmp = strdup(app_id); + if (!tmp) { + wl_resource_post_no_memory(resource); + return; + } + + if (surface->toplevel->app_id) + free(surface->toplevel->app_id); + + surface->toplevel->app_id= tmp; + wl_signal_emit(&surface->toplevel->events.set_app_id, surface); + +} + +static void +xdg_toplevel_v6_handle_show_window_menu(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat_resource, + uint32_t serial, int32_t x, int32_t y) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_move(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat_resource, + uint32_t serial) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_resize(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat_resource, + uint32_t serial, uint32_t edges) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_set_max_size(struct wl_client *client, + struct wl_resource *resource, int32_t width, int32_t height) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + surface->toplevel->pending.max_width = width; + surface->toplevel->pending.max_height = height; +} + +static void +xdg_toplevel_v6_handle_set_min_size(struct wl_client *client, + struct wl_resource *resource, int32_t width, int32_t height) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + surface->toplevel->pending.min_width = width; + surface->toplevel->pending.min_height = height; +} + +static void +xdg_toplevel_v6_handle_set_maximized(struct wl_client *client, + struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + surface->toplevel->requested.maximized = true; + wl_signal_emit(&surface->toplevel->events.request_maximize, surface); + ds_xdg_surface_v6_schedule_configure(surface); +} + +static void +xdg_toplevel_v6_handle_unset_maximized(struct wl_client *client, + struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + surface->toplevel->requested.maximized = false; + wl_signal_emit(&surface->toplevel->events.request_maximize, surface); + ds_xdg_surface_v6_schedule_configure(surface); +} + +static void +xdg_toplevel_v6_handle_set_fullscreen(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *output_resource) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_unset_fullscreen(struct wl_client *client, + struct wl_resource *resource) +{ + // TODO +} + +static void +xdg_toplevel_v6_handle_set_minimized(struct wl_client *client, + struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + surface->toplevel->requested.minimized = true; + wl_signal_emit(&surface->toplevel->events.request_maximize, surface); +} + +static const struct zxdg_toplevel_v6_interface xdg_toplevel_v6_impl = +{ + xdg_toplevel_v6_handle_destroy, + xdg_toplevel_v6_handle_set_parent, + xdg_toplevel_v6_handle_set_title, + xdg_toplevel_v6_handle_set_app_id, + xdg_toplevel_v6_handle_show_window_menu, + xdg_toplevel_v6_handle_move, + xdg_toplevel_v6_handle_resize, + xdg_toplevel_v6_handle_set_max_size, + xdg_toplevel_v6_handle_set_min_size, + xdg_toplevel_v6_handle_set_maximized, + xdg_toplevel_v6_handle_unset_maximized, + xdg_toplevel_v6_handle_set_fullscreen, + xdg_toplevel_v6_handle_unset_fullscreen, + xdg_toplevel_v6_handle_set_minimized, +}; + +static void +xdg_toplevel_v6_handle_resource_destroy(struct wl_resource *resource) +{ + struct ds_xdg_surface_v6 *surface; + + surface = wl_resource_get_user_data(resource); + if (!surface) + return; + + destroy_xdg_toplevel_v6(surface); +} -- 2.7.4 From 19f25a8373a5cf8dbb7b399a28ed89c4e938d015 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 4 Jul 2022 19:32:47 +0900 Subject: [PATCH 07/16] fix the typo Change-Id: I5185751f56cd506e1f458e51d40fb9758cc9aa61 --- src/shell.c | 2 +- src/xdg_shell/xdg_shell.c | 2 +- src/xdg_shell_v6/xdg_shell_v6.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shell.c b/src/shell.c index 3adb519..e9b42b4 100644 --- a/src/shell.c +++ b/src/shell.c @@ -13,7 +13,7 @@ static void shell_handle_display_destroy(struct wl_listener *listener, void *data); static void shell_bind(struct wl_client *wl_client, void *data, - uint32_t verison, uint32_t id); + uint32_t version, uint32_t id); WL_EXPORT struct ds_shell * ds_shell_create(struct wl_display *display) diff --git a/src/xdg_shell/xdg_shell.c b/src/xdg_shell/xdg_shell.c index 0b5252c..57096ea 100644 --- a/src/xdg_shell/xdg_shell.c +++ b/src/xdg_shell/xdg_shell.c @@ -13,7 +13,7 @@ static void xdg_shell_handle_display_destroy(struct wl_listener *listener, void *data); static void xdg_shell_bind(struct wl_client *wl_client, void *data, - uint32_t verison, uint32_t id); + uint32_t version, uint32_t id); WL_EXPORT struct ds_xdg_shell * ds_xdg_shell_create(struct wl_display *display) diff --git a/src/xdg_shell_v6/xdg_shell_v6.c b/src/xdg_shell_v6/xdg_shell_v6.c index 7702d73..af8b81c 100644 --- a/src/xdg_shell_v6/xdg_shell_v6.c +++ b/src/xdg_shell_v6/xdg_shell_v6.c @@ -13,7 +13,7 @@ static void xdg_shell_v6_handle_display_destroy(struct wl_listener *listener, void *data); static void xdg_shell_v6_bind(struct wl_client *wl_client, void *data, - uint32_t verison, uint32_t id); + uint32_t version, uint32_t id); WL_EXPORT struct ds_xdg_shell_v6 * ds_xdg_shell_v6_create(struct wl_display *display) -- 2.7.4 From ee6c90399c436d8be4c86527a7de964fb78f2f53 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 29 Jun 2022 16:19:52 +0900 Subject: [PATCH 08/16] seat: Add ds_seat_set_keyboard() The ds_seat_set_keyboard() enables a seat to refer to a ds_keyboard, so that the seat reads keymap and repeat info from ds_keyboard and then sends them to the wayland clients. Change-Id: Ic20fa041f391d0f8c73c8a6818505525701e3929 --- include/libds/seat.h | 2 + src/keyboard.c | 31 ++++++++++ src/keyboard.h | 12 ++++ src/seat/seat_keyboard.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++- src/seat/seat_private.h | 4 ++ 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 src/keyboard.h diff --git a/include/libds/seat.h b/include/libds/seat.h index e55fc4c..928861d 100644 --- a/include/libds/seat.h +++ b/include/libds/seat.h @@ -95,6 +95,8 @@ void ds_seat_set_capabilities(struct ds_seat *seat, void ds_seat_set_name(struct ds_seat *seat, const char *name); +void ds_seat_set_keyboard(struct ds_seat *seat, struct ds_input_device *device); + void ds_seat_add_destroy_listener(struct ds_seat *seat, struct wl_listener *listener); diff --git a/src/keyboard.c b/src/keyboard.c index d122e81..72467ee 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -246,6 +246,10 @@ ds_keyboard_init(struct ds_keyboard *keyboard, keyboard->iface = iface; keyboard->keymap_fd = -1; + // Sane defaults + keyboard->repeat_info.rate = 25; + keyboard->repeat_info.delay = 600; + wl_signal_init(&keyboard->events.destroy); wl_signal_init(&keyboard->events.key); wl_signal_init(&keyboard->events.modifiers); @@ -262,6 +266,33 @@ ds_keyboard_destroy(struct ds_keyboard *keyboard) free(keyboard); } +bool +ds_keyboard_get_keymap_fd(struct ds_keyboard *keyboard, int *keymap_fd, + size_t *keymap_size) +{ + if (keyboard->keymap_fd < 0) + return false; + + if (keymap_fd) + *keymap_fd = keyboard->keymap_fd; + + if (keymap_size) + *keymap_size = keyboard->keymap_size; + + return true; +} + +void +ds_keyboard_get_repeat_info(struct ds_keyboard *keyboard, int32_t *rate, + int32_t *delay) +{ + if (rate) + *rate = keyboard->repeat_info.rate; + + if (delay) + *delay = keyboard->repeat_info.delay; +} + static bool keyboard_modifier_update(struct ds_keyboard *keyboard) { diff --git a/src/keyboard.h b/src/keyboard.h new file mode 100644 index 0000000..193501d --- /dev/null +++ b/src/keyboard.h @@ -0,0 +1,12 @@ +#ifndef DS_KEYBOARD_H +#define DS_KEYBOARD_H + +#include "libds/keyboard.h" + +bool ds_keyboard_get_keymap_fd(struct ds_keyboard *keyboard, int *keymap_fd, + size_t *keymap_size); + +void ds_keyboard_get_repeat_info(struct ds_keyboard *keyboard, int32_t *rate, + int32_t *delay); + +#endif diff --git a/src/seat/seat_keyboard.c b/src/seat/seat_keyboard.c index b022163..4846711 100644 --- a/src/seat/seat_keyboard.c +++ b/src/seat/seat_keyboard.c @@ -4,6 +4,7 @@ #include #include "libds/log.h" +#include "keyboard.h" #include "seat_private.h" static const struct ds_keyboard_grab_interface default_keyboard_grab_iface; @@ -12,10 +13,47 @@ static const struct wl_keyboard_interface keyboard_impl; static void seat_client_send_keyboard_leave_raw(struct ds_seat_client *seat_client, struct ds_surface *surface); -static void -seat_keyboard_handle_surface_destroy(struct wl_listener *listener, +static void seat_client_send_keymap(struct ds_seat_client *seat_client, + struct ds_keyboard *ds_keyboard); +static void seat_client_send_repeat_info(struct ds_seat_client *seat_client, + struct ds_keyboard *ds_keyboard); +static void seat_keyboard_handle_surface_destroy(struct wl_listener *listener, void *data); static void keyboard_handle_resource_destroy(struct wl_resource *resource); +static void seat_keyboard_set_keyboard(struct ds_seat_keyboard *keyboard, + struct ds_input_device *device); +static void seat_keyboard_unset_keyboard(struct ds_seat_keyboard *keyboard); +static void seat_keyboard_handle_keyboard_destroy(struct wl_listener *listener, + void *data); +static void seat_keyboard_handle_keymap(struct wl_listener *listener, + void *data); +static void seat_keyboard_handle_repeat_info(struct wl_listener *listener, + void *data); + +WL_EXPORT void +ds_seat_set_keyboard(struct ds_seat *seat, struct ds_input_device *device) +{ + struct ds_seat_keyboard *keyboard = &seat->keyboard; + struct ds_keyboard *ds_keyboard = NULL; + + if (device) { + if (ds_input_device_get_type(device) != DS_INPUT_DEVICE_KEYBOARD) { + ds_err("Given device is not a keyboard"); + return; + } + + ds_keyboard = ds_input_device_get_keyboard(device); + } + + if (keyboard->ds_keyboard == ds_keyboard) + return; + + if (keyboard->ds_keyboard) + seat_keyboard_unset_keyboard(keyboard); + + if (ds_keyboard) + seat_keyboard_set_keyboard(keyboard, device); +} WL_EXPORT void ds_seat_keyboard_notify_enter(struct ds_seat *seat, @@ -293,6 +331,7 @@ seat_client_add_keyboard_resource(struct ds_seat_client *seat_client, uint32_t version, uint32_t id) { struct wl_resource *resource; + struct ds_keyboard *ds_keyboard; resource = wl_resource_create(seat_client->wl_client, &wl_keyboard_interface, version, id); @@ -310,6 +349,13 @@ seat_client_add_keyboard_resource(struct ds_seat_client *seat_client, wl_resource_set_user_data(resource, NULL); return; } + + ds_keyboard = seat_client->seat->keyboard.ds_keyboard; + if (!ds_keyboard) + return; + + seat_client_send_keymap(seat_client, ds_keyboard); + seat_client_send_repeat_info(seat_client, ds_keyboard); } void @@ -401,6 +447,43 @@ seat_client_send_keyboard_leave_raw(struct ds_seat_client *seat_client, } static void +seat_client_send_keymap(struct ds_seat_client *seat_client, + struct ds_keyboard *ds_keyboard) +{ + struct wl_resource *resource; + int fd; + size_t size; + + if (!ds_keyboard_get_keymap_fd(ds_keyboard, &fd, &size)) { + ds_err("Failed to get keymap fd from ds_keyboard(%p)", ds_keyboard); + return; + } + + wl_resource_for_each(resource, &seat_client->keyboards) { + wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, + fd, size); + } +} + +static void +seat_client_send_repeat_info(struct ds_seat_client *seat_client, + struct ds_keyboard *ds_keyboard) +{ + struct wl_resource *resource; + int32_t rate, delay; + + ds_keyboard_get_repeat_info(ds_keyboard, &rate, &delay); + + wl_resource_for_each(resource, &seat_client->keyboards) { + if (wl_resource_get_version(resource) < + WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) + continue; + + wl_keyboard_send_repeat_info(resource, rate, delay); + } +} + +static void seat_keyboard_handle_surface_destroy(struct wl_listener *listener, void *data) { @@ -412,3 +495,72 @@ seat_keyboard_handle_surface_destroy(struct wl_listener *listener, wl_list_init(&keyboard->surface_destroy.link); ds_seat_keyboard_clear_focus(keyboard->seat); } + +static void +seat_keyboard_set_keyboard(struct ds_seat_keyboard *keyboard, + struct ds_input_device *device) +{ + struct ds_seat_client *seat_client; + + keyboard->ds_keyboard = ds_input_device_get_keyboard(device); + + keyboard->keyboard_destroy.notify = seat_keyboard_handle_keyboard_destroy; + ds_input_device_add_destroy_listener(device, &keyboard->keyboard_destroy); + + keyboard->keymap.notify = seat_keyboard_handle_keymap; + ds_keyboard_add_keymap_listener(keyboard->ds_keyboard, &keyboard->keymap); + + keyboard->repeat_info.notify = seat_keyboard_handle_repeat_info; + ds_keyboard_add_repeat_info_listener(keyboard->ds_keyboard, + &keyboard->repeat_info); + + wl_list_for_each(seat_client, &keyboard->seat->clients, link) { + seat_client_send_keymap(seat_client, keyboard->ds_keyboard); + seat_client_send_repeat_info(seat_client, keyboard->ds_keyboard); + } +} + +static void +seat_keyboard_unset_keyboard(struct ds_seat_keyboard *keyboard) +{ + wl_list_remove(&keyboard->keyboard_destroy.link); + wl_list_remove(&keyboard->keymap.link); + wl_list_remove(&keyboard->repeat_info.link); + + keyboard->ds_keyboard = NULL; +} + +static void +seat_keyboard_handle_keyboard_destroy(struct wl_listener *listener, void *data) +{ + struct ds_seat_keyboard *keyboard; + + keyboard = wl_container_of(listener, keyboard, keyboard_destroy); + + seat_keyboard_unset_keyboard(keyboard); +} + +static void +seat_keyboard_handle_keymap(struct wl_listener *listener, void *data) +{ + struct ds_seat_keyboard *keyboard; + struct ds_seat_client *seat_client; + + keyboard = wl_container_of(listener, keyboard, keymap); + + wl_list_for_each(seat_client, &keyboard->seat->clients, link) + seat_client_send_keymap(seat_client, keyboard->ds_keyboard); +} + +static void +seat_keyboard_handle_repeat_info(struct wl_listener *listener, + void *data) +{ + struct ds_seat_keyboard *keyboard; + struct ds_seat_client *seat_client; + + keyboard = wl_container_of(listener, keyboard, repeat_info); + + wl_list_for_each(seat_client, &keyboard->seat->clients, link) + seat_client_send_repeat_info(seat_client, keyboard->ds_keyboard); +} diff --git a/src/seat/seat_private.h b/src/seat/seat_private.h index 7a566bb..eeaa6ba 100644 --- a/src/seat/seat_private.h +++ b/src/seat/seat_private.h @@ -57,11 +57,15 @@ struct ds_seat_pointer struct ds_seat_keyboard { struct ds_seat *seat; + struct ds_keyboard *ds_keyboard; struct ds_seat_client *focused_client; struct ds_surface *focused_surface; struct wl_listener surface_destroy; + struct wl_listener keyboard_destroy; + struct wl_listener keymap; + struct wl_listener repeat_info; struct ds_seat_keyboard_grab *grab; struct ds_seat_keyboard_grab *default_grab; -- 2.7.4 From 6862ef22c2a7ccbb4d9400e7443626bdf4bd6b89 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 5 Jul 2022 19:53:07 +0900 Subject: [PATCH 09/16] surface: Export ds_surface_get_wl_resource() Change-Id: Icf1a5a2ac9548817ce37d27a7f92ca9b55586804 --- include/libds/surface.h | 3 +++ src/surface.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/libds/surface.h b/include/libds/surface.h index 3d014dc..cef69f7 100644 --- a/include/libds/surface.h +++ b/include/libds/surface.h @@ -61,6 +61,9 @@ ds_surface_get_role_data(struct ds_surface *surface); void ds_surface_reset_role_data(struct ds_surface *surface); +struct wl_resource * +ds_surface_get_wl_resource(struct ds_surface *surface); + #ifdef __cplusplus } #endif diff --git a/src/surface.h b/src/surface.h index c1cc358..a797bd0 100644 --- a/src/surface.h +++ b/src/surface.h @@ -23,7 +23,4 @@ ds_subsurface_create(struct wl_resource *subcomp_resource, struct ds_surface *surface, struct ds_surface *parent, uint32_t version, uint32_t id); -struct wl_resource * -ds_surface_get_wl_resource(struct ds_surface *surface); - #endif -- 2.7.4 From e30fb49b70feb11340ad459347e7978838ea3e40 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 6 Jul 2022 09:25:07 +0900 Subject: [PATCH 10/16] seat: Add API for keyrouter The keyrouter module which lives in libds-tizen project needs to send keyboard key events to several wl_clients according to its policy. To support this functionality, this patch implements related API. Among them, the notable API is ds_seat_client_send_key() which enables keyrouter to send keyboard key events to non-focused wl_client. Change-Id: I8cfd47d6ed6536163d0eb1bb0102fb102d78afd9 --- include/libds/seat.h | 14 ++++++++++++++ src/seat/seat.c | 20 ++++++++++++++++++++ src/seat/seat_keyboard.c | 24 +++++++++++++++++++----- src/seat/seat_private.h | 3 +++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/include/libds/seat.h b/include/libds/seat.h index 928861d..8790bf9 100644 --- a/include/libds/seat.h +++ b/include/libds/seat.h @@ -10,6 +10,8 @@ struct ds_seat; +struct ds_seat_client; + enum ds_axis_orientation { DS_AXIS_ORIENTATION_VERTICAL, @@ -100,6 +102,15 @@ void ds_seat_set_keyboard(struct ds_seat *seat, struct ds_input_device *device); void ds_seat_add_destroy_listener(struct ds_seat *seat, struct wl_listener *listener); +struct ds_seat_client *ds_seat_client_for_wl_client(struct ds_seat *seat, + struct wl_client *wl_client); + +void ds_seat_client_add_destroy_listener(struct ds_seat_client *seat_client, + struct wl_listener *listener); + +void ds_seat_client_send_key(struct ds_seat_client *seat_client, + uint32_t time_msec, uint32_t key, uint32_t state); + void ds_seat_pointer_notify_enter(struct ds_seat *seat, struct ds_surface *surface, double sx, double sy); @@ -164,6 +175,9 @@ void ds_seat_keyboard_add_grab_end_listener(struct ds_seat *seat, void ds_seat_keyboard_add_focus_change_listener(struct ds_seat *seat, struct wl_listener *listener); +struct ds_seat_client * +ds_seat_keyboard_get_focused_client(struct ds_seat *seat); + void ds_seat_touch_end_grab_start_listener(struct ds_seat *seat, struct wl_listener *listener); diff --git a/src/seat/seat.c b/src/seat/seat.c index 51d5c23..bec9059 100644 --- a/src/seat/seat.c +++ b/src/seat/seat.c @@ -136,6 +136,26 @@ ds_seat_add_destroy_listener(struct ds_seat *seat, wl_signal_add(&seat->events.destroy, listener); } +WL_EXPORT void +ds_seat_client_send_key(struct ds_seat_client *seat_client, + uint32_t time_msec, uint32_t key, uint32_t state) +{ + seat_client_send_key(seat_client, time_msec, key, state); +} + +WL_EXPORT struct ds_seat_client * +ds_seat_client_for_wl_client(struct ds_seat *seat, struct wl_client *wl_client) +{ + return seat_client_for_wl_client(seat, wl_client); +} + +WL_EXPORT void +ds_seat_client_add_destroy_listener(struct ds_seat_client *seat_client, + struct wl_listener *listener) +{ + wl_signal_add(&seat_client->events.destroy, listener); +} + struct ds_seat_client * seat_client_for_wl_client(struct ds_seat *seat, struct wl_client *wl_client) { diff --git a/src/seat/seat_keyboard.c b/src/seat/seat_keyboard.c index 4846711..de2d3df 100644 --- a/src/seat/seat_keyboard.c +++ b/src/seat/seat_keyboard.c @@ -30,6 +30,12 @@ static void seat_keyboard_handle_keymap(struct wl_listener *listener, static void seat_keyboard_handle_repeat_info(struct wl_listener *listener, void *data); +WL_EXPORT struct ds_seat_client * +ds_seat_keyboard_get_focused_client(struct ds_seat *seat) +{ + return seat->keyboard.focused_client; +} + WL_EXPORT void ds_seat_set_keyboard(struct ds_seat *seat, struct ds_input_device *device) { @@ -257,16 +263,12 @@ ds_seat_keyboard_send_key(struct ds_seat *seat, uint32_t time_msec, uint32_t key, uint32_t state) { struct ds_seat_client *seat_client; - struct wl_resource *resource; - uint32_t serial; seat_client = seat->keyboard.focused_client; if (!seat_client) return; - serial = wl_display_next_serial(seat->display); - wl_resource_for_each(resource, &seat_client->keyboards) - wl_keyboard_send_key(resource, serial, time_msec, key, state); + seat_client_send_key(seat_client, time_msec, key, state); } void @@ -369,6 +371,18 @@ seat_client_remove_all_keyboard_resources(struct ds_seat_client *seat_client) } } +void +seat_client_send_key(struct ds_seat_client *seat_client, uint32_t time_msec, + uint32_t key, uint32_t state) +{ + struct wl_resource *resource; + uint32_t serial; + + serial = wl_display_next_serial(seat_client->seat->display); + wl_resource_for_each(resource, &seat_client->keyboards) + wl_keyboard_send_key(resource, serial, time_msec, key, state); +} + static void keyboard_handle_release(struct wl_client *client, struct wl_resource *resource) { diff --git a/src/seat/seat_private.h b/src/seat/seat_private.h index eeaa6ba..7a3bda6 100644 --- a/src/seat/seat_private.h +++ b/src/seat/seat_private.h @@ -173,4 +173,7 @@ void seat_client_add_touch_resource(struct ds_seat_client *seat_client, void seat_client_remove_all_touch_resources(struct ds_seat_client *seat_client); +void seat_client_send_key(struct ds_seat_client *seat_client, + uint32_t time_msec, uint32_t key, uint32_t state); + #endif -- 2.7.4 From 40cf90b0e2ab998038d6e72640cd5f3fba718f4d Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 12 Jul 2022 10:17:10 +0900 Subject: [PATCH 11/16] xdg_shell_v6: Remove 'xdg-shell-unstable-v6-server' dependency The rpm package 'xdg-shell-unstable-v6-server' isn't always provided on every platform. So, this patch generates code and header from wayland-protocols using wayland-scanner. Change-Id: I8dc7e751b1f9a2d2c02fb339efd2d620dfb63f7a --- packaging/libds.spec | 1 - src/xdg_shell_v6/meson.build | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packaging/libds.spec b/packaging/libds.spec index 13d59cf..ac79499 100644 --- a/packaging/libds.spec +++ b/packaging/libds.spec @@ -11,7 +11,6 @@ BuildRequires: meson BuildRequires: pkgconfig(wayland-server) BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(wayland-protocols) -BuildRequires: pkgconfig(xdg-shell-unstable-v6-server) BuildRequires: pkgconfig(pixman-1) BuildRequires: pkgconfig(libdrm) BuildRequires: pkgconfig(xkbcommon) diff --git a/src/xdg_shell_v6/meson.build b/src/xdg_shell_v6/meson.build index 55c9b85..d584968 100644 --- a/src/xdg_shell_v6/meson.build +++ b/src/xdg_shell_v6/meson.build @@ -4,9 +4,28 @@ libds_xdg_shell_v6_files = [ 'xdg_toplevel_v6.c', ] +protocol_name = 'xdg-shell-v6' +protocol_path = wl_protocol_dir / 'unstable/xdg-shell/xdg-shell-unstable-v6.xml' + +code = custom_target( + protocol_name.underscorify() + '_c', + input: protocol_path, + output: '@BASENAME@-protocol.c', + command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'], +) +libds_xdg_shell_v6_files += code + +server_header = custom_target( + protocol_name.underscorify() + '_server_h', + input: protocol_path, + output: '@BASENAME@-server-protocol.h', + command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'], + build_by_default: false, +) +libds_xdg_shell_v6_files += server_header + libds_xdg_shell_v6_deps = [ dep_libds, - dependency('xdg-shell-unstable-v6-server', required: true), ] lib_libds_xdg_shell_v6 = shared_library('ds-xdg-shell-v6', libds_xdg_shell_v6_files, -- 2.7.4 From 42a84868ccac3a2bc2fbe7e08ad90837f5b63805 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 13 Jul 2022 12:09:31 +0900 Subject: [PATCH 12/16] tinyds: Notify button event of pointer Change-Id: Ie4ec66d5823978fa3a04b3cafa7dbc95ce8fdd38 --- examples/tinyds.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/tinyds.c b/examples/tinyds.c index 0e25462..26c08c5 100644 --- a/examples/tinyds.c +++ b/examples/tinyds.c @@ -405,6 +405,9 @@ pointer_handle_button(struct wl_listener *listener, void *data) pointer, event->button, (event->state == DS_BUTTON_PRESSED) ? "Pressed" : "Released", event->time_msec); + + ds_seat_pointer_notify_button(pointer->server->seat, event->time_msec, + event->button, event->state); } static void -- 2.7.4 From 49b6ebc6df66cb1b79f64af36b082c4ebb8b7620 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 13 Jul 2022 12:18:21 +0900 Subject: [PATCH 13/16] backend-wayland: Fix using uninitialized data Change-Id: Ia37e244b20dbc8f715d17c86ba92385571b5873f --- src/backend/wayland/output.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/wayland/output.c b/src/backend/wayland/output.c index 7728abf..a5b7c12 100644 --- a/src/backend/wayland/output.c +++ b/src/backend/wayland/output.c @@ -229,6 +229,12 @@ create_wl_buffer(struct ds_wl_backend *backend, struct ds_buffer *ds_buffer) if (ds_buffer_get_shm(ds_buffer, &shm)) { wl_buffer = import_shm(backend, &shm); } + else { + return NULL; + } + + if (!wl_buffer) + return NULL; buffer = calloc(1, sizeof *buffer); if (!buffer) { -- 2.7.4 From df6e36f175d31ee3fb07e5d55389e880315c6e0b Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 13 Jul 2022 12:50:08 +0900 Subject: [PATCH 14/16] region: Remove unreachable code And this also adds an assert when unknown transform is given. Change-Id: Ic2e9b01ce2106f02f4a4032f2125a8fa9153ae54 --- src/region.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/region.c b/src/region.c index 92fe003..966fc1a 100644 --- a/src/region.c +++ b/src/region.c @@ -63,14 +63,6 @@ ds_region_transform(pixman_region32_t *dst, pixman_region32_t *src, for (i = 0; i < nrects; i++) { switch (transform) { - default: - ds_err("Unkown transform value(%d)", transform); - case WL_OUTPUT_TRANSFORM_NORMAL: - dst_rects[i].x1 = src_rects[i].x1; - dst_rects[i].y1 = src_rects[i].y1; - dst_rects[i].x2 = src_rects[i].x2; - dst_rects[i].y2 = src_rects[i].y2; - break; case WL_OUTPUT_TRANSFORM_90: dst_rects[i].x1 = height - src_rects[i].y2; dst_rects[i].y1 = src_rects[i].x1; @@ -113,6 +105,10 @@ ds_region_transform(pixman_region32_t *dst, pixman_region32_t *src, dst_rects[i].x2 = height - src_rects[i].y1; dst_rects[i].y2 = width - src_rects[i].x1; break; + default: + ds_err("Unkown transform value(%d)", transform); + assert(0 && "Cannot reach here"); + break; } } -- 2.7.4 From b403f9e0dc4417ee545b15b2ff559eb69c76828a Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 13 Jul 2022 13:42:09 +0900 Subject: [PATCH 15/16] shm: Use snprintf() instead of vulnerable strcat() Change-Id: I0c7a2dd640993387dcaf1bf8f1db0eae593b4030 --- src/util/shm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/shm.c b/src/util/shm.c index 4abd229..4c94b79 100644 --- a/src/util/shm.c +++ b/src/util/shm.c @@ -25,6 +25,7 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -119,6 +120,7 @@ allocate_shm_file(off_t size) static const char template[] = "/weston-shared-XXXXXX"; const char *path; char *name; + size_t name_size; int fd; int ret; @@ -141,12 +143,12 @@ allocate_shm_file(off_t size) return -1; } - name = malloc(strlen(path) + sizeof(template)); + name_size = strlen(path) + sizeof(template); + name = malloc(name_size); if (!name) return -1; - strcpy(name, path); - strcat(name, template); + snprintf(name, name_size, "%s%s", path, template); fd = create_tmpfile_cloexec(name); -- 2.7.4 From 23f35d7ce1effbc7d0dd00ea386ae6c514578849 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 13 Jul 2022 13:50:19 +0900 Subject: [PATCH 16/16] xdg_shell, xdg_shell_v6: Remove unreachable code Change-Id: I2ffdb8d385f5cfc07b272505e134f04b16bd7859 --- src/xdg_shell/xdg_surface.c | 6 +++--- src/xdg_shell_v6/xdg_surface_v6.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xdg_shell/xdg_surface.c b/src/xdg_shell/xdg_surface.c index 1e1654e..35ca7a7 100644 --- a/src/xdg_shell/xdg_surface.c +++ b/src/xdg_shell/xdg_surface.c @@ -396,14 +396,14 @@ xdg_surface_handle_ack_configure(struct wl_client *client, } switch (surface->role) { - case DS_XDG_SURFACE_ROLE_NONE: - assert(0 && "not reached"); - break; case DS_XDG_SURFACE_ROLE_TOPLEVEL: // TODO break; case DS_XDG_SURFACE_ROLE_POPUP: break; + default: + assert(0 && "not reached"); + break; } surface->configured = true; diff --git a/src/xdg_shell_v6/xdg_surface_v6.c b/src/xdg_shell_v6/xdg_surface_v6.c index 69ab595..487ad45 100644 --- a/src/xdg_shell_v6/xdg_surface_v6.c +++ b/src/xdg_shell_v6/xdg_surface_v6.c @@ -402,14 +402,14 @@ xdg_surface_v6_handle_ack_configure(struct wl_client *client, } switch (surface->role) { - case DS_XDG_SURFACE_V6_ROLE_NONE: - assert(0 && "not reached"); - break; case DS_XDG_SURFACE_V6_ROLE_TOPLEVEL: // TODO break; case DS_XDG_SURFACE_V6_ROLE_POPUP: break; + default: + assert(0 && "not reached"); + break; } surface->configured = true; -- 2.7.4